Passed
Pull Request — master (#83)
by Glynn
05:41
created
src/Services/View/Component/Component_Compiler.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	private $component_aliases = array();
51 51
 
52 52
 	/** @param array<string, string> $component_aliases */
53
-	public function __construct( string $component_base_path = '', array $component_aliases = array() ) {
53
+	public function __construct(string $component_base_path = '', array $component_aliases = array()) {
54 54
 		$this->component_base_path = $component_base_path;
55 55
 		$this->component_aliases   = $component_aliases;
56 56
 	}
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @param Component $component
62 62
 	 * @return View_Model
63 63
 	 */
64
-	public function compile( Component $component ): View_Model {
65
-		return new View_Model( $this->get_component_path( $component ), $component->get_variables() );
64
+	public function compile(Component $component): View_Model {
65
+		return new View_Model($this->get_component_path($component), $component->get_variables());
66 66
 	}
67 67
 
68 68
 	/**
@@ -71,34 +71,34 @@  discard block
 block discarded – undo
71 71
 	 * @param Component $component
72 72
 	 * @return string
73 73
 	 */
74
-	private function get_component_path( Component $component ): string {
74
+	private function get_component_path(Component $component): string {
75 75
 
76 76
 		// Check aliases.
77
-		$aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $this->component_aliases );
77
+		$aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $this->component_aliases);
78 78
 
79
-		if ( isset( $aliases[ get_class( $component ) ] ) ) {
80
-			return esc_attr( $aliases[ get_class( $component ) ] );
79
+		if (isset($aliases[get_class($component)])) {
80
+			return esc_attr($aliases[get_class($component)]);
81 81
 		}
82 82
 
83
-		$from_annotation = $this->get_annotation( 'view', $component );
83
+		$from_annotation = $this->get_annotation('view', $component);
84 84
 		// If it does have a path defined, use that.
85
-		if ( ! empty( $from_annotation ) ) {
86
-			return \trailingslashit( $this->component_base_path ) . $from_annotation;
85
+		if ( ! empty($from_annotation)) {
86
+			return \trailingslashit($this->component_base_path) . $from_annotation;
87 87
 		}
88 88
 
89 89
 		// If the component has a defined path
90
-		if ( $component->template() ) {
91
-			return \trailingslashit( $this->component_base_path ) . $component->template();
90
+		if ($component->template()) {
91
+			return \trailingslashit($this->component_base_path) . $component->template();
92 92
 		}
93 93
 
94 94
 		// Get path based on class name.
95
-		$reflect    = new \ReflectionClass( $component );
95
+		$reflect    = new \ReflectionClass($component);
96 96
 		$short_name = $reflect->getShortName();
97 97
 		// Add space between capitals, make lowercase and replace underscores with dashes.
98
-		$short_name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $short_name ) ?? '' );
99
-		$short_name = str_replace( '_', '-', $short_name );
98
+		$short_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $short_name) ?? '');
99
+		$short_name = str_replace('_', '-', $short_name);
100 100
 
101
-		return \trailingslashit( $this->component_base_path ) . $short_name;
101
+		return \trailingslashit($this->component_base_path) . $short_name;
102 102
 	}
103 103
 
104 104
 	/**
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
 	 * @param Component $component
109 109
 	 * @return string|null
110 110
 	 */
111
-	private function get_annotation( string $annotation, Component $component ): ?string {
112
-		$reflect = new \ReflectionClass( $component );
111
+	private function get_annotation(string $annotation, Component $component): ?string {
112
+		$reflect = new \ReflectionClass($component);
113 113
 		$comment = $reflect->getDocComment();
114 114
 
115 115
 		// if no comment, return null.
116
-		if ( empty( $comment ) ) {
116
+		if (empty($comment)) {
117 117
 			return null;
118 118
 		}
119 119
 
120 120
 		// If comment contains the annotation, return the value.
121
-		return strpos( $comment, "@{$annotation}" ) !== false
122
-			? $this->extract_annotation_value( $comment, $annotation )
121
+		return strpos($comment, "@{$annotation}") !== false
122
+			? $this->extract_annotation_value($comment, $annotation)
123 123
 			: null;
124 124
 	}
125 125
 
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 	 * @param string $annotation
131 131
 	 * @return string|null
132 132
 	 */
133
-	private function extract_annotation_value( string $comment, string $annotation ): ?string {
133
+	private function extract_annotation_value(string $comment, string $annotation): ?string {
134 134
 		$pattern = "/@{$annotation}\s+(.*)/";
135
-		preg_match( $pattern, $comment, $matches );
135
+		preg_match($pattern, $comment, $matches);
136 136
 		return $matches[1] ?? null;
137 137
 	}
138 138
 
Please login to merge, or discard this patch.