• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 7004843404

27 Nov 2023 11:48AM UTC coverage: 49.206% (-0.03%) from 49.232%
7004843404

push

github

web-flow
Merge pull request #20858 from Yoast/improve-copy-in-the-ftc-57

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.33
/src/surfaces/schema-helpers-surface.php
1
<?php
2

3
namespace Yoast\WP\SEO\Surfaces;
4

5
use Yoast\WP\SEO\Exceptions\Forbidden_Property_Mutation_Exception;
6
use Yoast\WP\SEO\Helpers\Schema;
7
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
8

9
/**
10
 * Class Schema_Helpers_Surface.
11
 *
12
 * Surface for the indexables.
13
 *
14
 * @property Schema\Article_Helper $article
15
 * @property Schema\HTML_Helper $html
16
 * @property Schema\ID_Helper $id
17
 * @property Schema\Image_Helper $image
18
 * @property Schema\Language_Helper $language
19
 */
20
class Schema_Helpers_Surface {
21

22
        /**
23
         * The DI container.
24
         *
25
         * @var ContainerInterface
26
         */
27
        private $container;
28

29
        /**
30
         * Helpers that should be fully capitalized.
31
         *
32
         * @var array
33
         */
34
        private $capitalized_helpers = [ 'html', 'id' ];
35

36
        /**
37
         * Loader constructor.
38
         *
39
         * @param ContainerInterface $container The dependency injection container.
40
         */
41
        public function __construct( ContainerInterface $container ) {
×
42
                $this->container = $container;
×
43
        }
44

45
        /**
46
         * Magic getter for getting helper classes.
47
         *
48
         * @param string $helper The helper to get.
49
         *
50
         * @return mixed The helper class.
51
         */
52
        public function __get( $helper ) {
20✔
53
                return $this->container->get( $this->get_helper_class( $helper ) );
20✔
54
        }
55

56
        /**
57
         * Magic isset for ensuring helper exists.
58
         *
59
         * @param string $helper The helper to get.
60
         *
61
         * @return bool Whether the helper exists.
62
         */
63
        public function __isset( $helper ) {
20✔
64
                return $this->container->has( $this->get_helper_class( $helper ) );
20✔
65
        }
66

67
        /**
68
         * Prevents setting dynamic properties and unsetting declared properties
69
         * from an inaccessible context.
70
         *
71
         * @param string $name  The property name.
72
         * @param mixed  $value The property value.
73
         *
74
         * @return void
75
         *
76
         * @throws Forbidden_Property_Mutation_Exception Set is never meant to be called.
77
         */
78
        public function __set( $name, $value ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- __set must have a name and value - PHPCS #3715.
10✔
79
                throw Forbidden_Property_Mutation_Exception::cannot_set_because_property_is_immutable( $name );
10✔
80
        }
81

82
        /**
83
         * Prevents unsetting dynamic properties and unsetting declared properties
84
         * from an inaccessible context.
85
         *
86
         * @param string $name The property name.
87
         *
88
         * @return void
89
         *
90
         * @throws Forbidden_Property_Mutation_Exception Unset is never meant to be called.
91
         */
92
        public function __unset( $name ) {
10✔
93
                throw Forbidden_Property_Mutation_Exception::cannot_unset_because_property_is_immutable( $name );
10✔
94
        }
95

96
        /**
97
         * Get the class name from a helper slug
98
         *
99
         * @param string $helper The name of the helper.
100
         *
101
         * @return string
102
         */
103
        protected function get_helper_class( $helper ) {
×
104
                if ( \in_array( $helper, $this->capitalized_helpers, true ) ) {
×
105
                        $helper = \strtoupper( $helper );
×
106
                }
107
                $helper = \implode( '_', \array_map( 'ucfirst', \explode( '_', $helper ) ) );
×
108
                return "Yoast\WP\SEO\Helpers\Schema\\{$helper}_Helper";
×
109
        }
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc