@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @param array<string, string> $component_aliases |
54 | 54 | */ |
55 | - public function __construct( string $component_base_path = '', array $component_aliases = array() ) { |
|
55 | + public function __construct(string $component_base_path = '', array $component_aliases = array()) { |
|
56 | 56 | $this->component_base_path = $component_base_path; |
57 | - $this->component_aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $component_aliases ); |
|
57 | + $this->component_aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $component_aliases); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * @param Component $component |
64 | 64 | * @return View_Model |
65 | 65 | */ |
66 | - public function compile( Component $component ): View_Model { |
|
67 | - return new View_Model( $this->get_component_path( $component ), $component->get_variables() ); |
|
66 | + public function compile(Component $component): View_Model { |
|
67 | + return new View_Model($this->get_component_path($component), $component->get_variables()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,34 +73,34 @@ discard block |
||
73 | 73 | * @param Component $component |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - private function get_component_path( Component $component ): string { |
|
76 | + private function get_component_path(Component $component): string { |
|
77 | 77 | |
78 | 78 | // Check aliases. |
79 | - $aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $this->component_aliases ); |
|
79 | + $aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $this->component_aliases); |
|
80 | 80 | |
81 | - if ( \array_key_exists( get_class( $component ), $this->component_aliases ) ) { |
|
82 | - return esc_attr( $aliases[ get_class( $component ) ] ); |
|
81 | + if (\array_key_exists(get_class($component), $this->component_aliases)) { |
|
82 | + return esc_attr($aliases[get_class($component)]); |
|
83 | 83 | } |
84 | 84 | |
85 | - $from_annotation = $this->get_annotation( 'view', $component ); |
|
85 | + $from_annotation = $this->get_annotation('view', $component); |
|
86 | 86 | |
87 | 87 | // If it does have a path defined, use that. |
88 | - if ( ! empty( $from_annotation ) ) { |
|
89 | - return \trailingslashit( $this->component_base_path ) . $from_annotation; |
|
88 | + if ( ! empty($from_annotation)) { |
|
89 | + return \trailingslashit($this->component_base_path) . $from_annotation; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // If the component has a defined path |
93 | - if ( $component->template() ) { |
|
94 | - return \trailingslashit( $this->component_base_path ) . $component->template(); |
|
93 | + if ($component->template()) { |
|
94 | + return \trailingslashit($this->component_base_path) . $component->template(); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Get path based on class name. |
98 | - $reflect = new \ReflectionClass( $component ); |
|
98 | + $reflect = new \ReflectionClass($component); |
|
99 | 99 | $short_name = $reflect->getShortName(); |
100 | 100 | // Add space between capitals, make lowercase and replace underscores with dashes. |
101 | - $short_name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '$0', $short_name ) ?? '' ); |
|
102 | - $short_name = str_replace( '_', '-', $short_name ); |
|
103 | - return \trailingslashit( $this->component_base_path ) . $short_name; |
|
101 | + $short_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '$0', $short_name) ?? ''); |
|
102 | + $short_name = str_replace('_', '-', $short_name); |
|
103 | + return \trailingslashit($this->component_base_path) . $short_name; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,18 +110,18 @@ discard block |
||
110 | 110 | * @param Component $component |
111 | 111 | * @return string|null |
112 | 112 | */ |
113 | - private function get_annotation( string $annotation, Component $component ): ?string { |
|
114 | - $reflect = new \ReflectionClass( $component ); |
|
113 | + private function get_annotation(string $annotation, Component $component): ?string { |
|
114 | + $reflect = new \ReflectionClass($component); |
|
115 | 115 | $comment = $reflect->getDocComment(); |
116 | 116 | |
117 | 117 | // if no comment, return null. |
118 | - if ( empty( $comment ) ) { |
|
118 | + if (empty($comment)) { |
|
119 | 119 | return null; |
120 | 120 | } |
121 | 121 | |
122 | 122 | // Check if the comment contains the annotation "@{$annotation}" using regex. |
123 | 123 | $pattern = "/@{$annotation}\s+(.*)/"; |
124 | - preg_match( $pattern, $comment, $matches ); |
|
124 | + preg_match($pattern, $comment, $matches); |
|
125 | 125 | |
126 | 126 | return $matches[1] ?? null; |
127 | 127 | } |