Passed
Push — master ( 9604c7...90a7ba )
by
unknown
01:48
created
src/Routing/Route.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -45,22 +45,22 @@  discard block
 block discarded – undo
45 45
 	 * @param mixed           $target
46 46
 	 * @param string|\Closure $handler
47 47
 	 */
48
-	public function __construct( $methods, $target, $handler ) {
49
-		if ( is_string( $target ) ) {
50
-			$target = new UrlCondition( $target );
48
+	public function __construct($methods, $target, $handler) {
49
+		if (is_string($target)) {
50
+			$target = new UrlCondition($target);
51 51
 		}
52 52
 
53
-		if ( is_array( $target ) ) {
54
-			$target = $this->condition( $target );
53
+		if (is_array($target)) {
54
+			$target = $this->condition($target);
55 55
 		}
56 56
 
57
-		if ( ! is_a( $target, ConditionInterface::class ) ) {
58
-			throw new Exception( 'Route target is not a valid route string or condition.' );
57
+		if ( ! is_a($target, ConditionInterface::class)) {
58
+			throw new Exception('Route target is not a valid route string or condition.');
59 59
 		}
60 60
 
61 61
 		$this->methods = $methods;
62 62
 		$this->target = $target;
63
-		$this->handler = new Handler( $handler );
63
+		$this->handler = new Handler($handler);
64 64
 	}
65 65
 
66 66
 	/**
@@ -69,41 +69,41 @@  discard block
 block discarded – undo
69 69
 	 * @param  array              $options
70 70
 	 * @return ConditionInterface
71 71
 	 */
72
-	protected function condition( $options ) {
73
-		if ( count( $options ) === 0 ) {
74
-			throw new Exception( 'No condition type specified.' );
72
+	protected function condition($options) {
73
+		if (count($options) === 0) {
74
+			throw new Exception('No condition type specified.');
75 75
 		}
76 76
 
77 77
 		$condition_type = $options[0];
78
-		$arguments = array_slice( $options, 1 );
78
+		$arguments = array_slice($options, 1);
79 79
 
80
-		$condition_class = Framework::resolve( 'framework.routing.conditions.' . $condition_type );
81
-		if ( $condition_class === null ) {
82
-			throw new Exception( 'Unknown condition type specified: ' . $condition_type );
80
+		$condition_class = Framework::resolve('framework.routing.conditions.' . $condition_type);
81
+		if ($condition_class === null) {
82
+			throw new Exception('Unknown condition type specified: ' . $condition_type);
83 83
 		}
84 84
 
85
-		$reflection = new ReflectionClass( $condition_class );
86
-		$condition = $reflection->newInstanceArgs( $arguments );
85
+		$reflection = new ReflectionClass($condition_class);
86
+		$condition = $reflection->newInstanceArgs($arguments);
87 87
 		return $condition;
88 88
 	}
89 89
 
90 90
 	/**
91 91
 	 * {@inheritDoc}
92 92
 	 */
93
-	public function satisfied( Request $request ) {
94
-		if ( ! in_array( $request->getMethod(), $this->methods) ) {
93
+	public function satisfied(Request $request) {
94
+		if ( ! in_array($request->getMethod(), $this->methods)) {
95 95
 			return false;
96 96
 		}
97
-		return $this->target->satisfied( $request );
97
+		return $this->target->satisfied($request);
98 98
 	}
99 99
 
100 100
 	/**
101 101
 	 * {@inheritDoc}
102 102
 	 */
103
-	public function handle( Request $request ) {
104
-		$arguments = array_merge( [$request], $this->target->getArguments( $request ) );
105
-		return $this->executeMiddleware( $this->getMiddleware(), $request, function() use ( $arguments ) {
106
-			return call_user_func_array( [$this->handler, 'execute'], $arguments );
103
+	public function handle(Request $request) {
104
+		$arguments = array_merge([$request], $this->target->getArguments($request));
105
+		return $this->executeMiddleware($this->getMiddleware(), $request, function() use ($arguments) {
106
+			return call_user_func_array([$this->handler, 'execute'], $arguments);
107 107
 		} );
108 108
 	}
109 109
 
@@ -113,16 +113,16 @@  discard block
 block discarded – undo
113 113
 	 * @param  string $rewrite_to
114 114
 	 * @return RouteInterface
115 115
 	 */
116
-	public function rewrite( $rewrite_to ) {
117
-		if ( ! is_a( $this->target, UrlCondition::class ) ) {
118
-			throw new Exception( 'Only routes with url targets can add rewrite rules.' );
116
+	public function rewrite($rewrite_to) {
117
+		if ( ! is_a($this->target, UrlCondition::class)) {
118
+			throw new Exception('Only routes with url targets can add rewrite rules.');
119 119
 		}
120 120
 
121
-		$regex = $this->target->getValidationRegex( $this->target->getUrl(), false );
122
-		$regex = preg_replace( '~^\^/~', '^', $regex ); // rewrite rules require NO leading slash
121
+		$regex = $this->target->getValidationRegex($this->target->getUrl(), false);
122
+		$regex = preg_replace('~^\^/~', '^', $regex); // rewrite rules require NO leading slash
123 123
 
124
-		add_filter( 'carbon_framework_routing_rewrite_rules', function( $rules ) use ( $regex, $rewrite_to ) {
125
-			$rules[ $regex ] = $rewrite_to;
124
+		add_filter('carbon_framework_routing_rewrite_rules', function($rules) use ($regex, $rewrite_to) {
125
+			$rules[$regex] = $rewrite_to;
126 126
 			return $rules;
127 127
 		} );
128 128
 
Please login to merge, or discard this patch.
src/Response.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
 	 * @param  ResponseInterface $response
27 27
 	 * @return null
28 28
 	 */
29
-	public static function respond( ResponseInterface $response ) {
30
-		if ( ! headers_sent() ) {
31
-			static::sendHeaders( $response );
29
+	public static function respond(ResponseInterface $response) {
30
+		if ( ! headers_sent()) {
31
+			static::sendHeaders($response);
32 32
 		}
33
-		static::sendBody( $response );
33
+		static::sendBody($response);
34 34
 	}
35 35
 
36 36
 	/**
@@ -39,19 +39,19 @@  discard block
 block discarded – undo
39 39
 	 * @param  ResponseInterface $response
40 40
 	 * @return null
41 41
 	 */
42
-	protected static function sendHeaders( $response ) {
42
+	protected static function sendHeaders($response) {
43 43
 		// Status
44
-		header( sprintf(
44
+		header(sprintf(
45 45
 			'HTTP/%s %s %s',
46 46
 			$response->getProtocolVersion(),
47 47
 			$response->getStatusCode(),
48 48
 			$response->getReasonPhrase()
49
-		) );
49
+		));
50 50
 
51 51
 		// Headers
52
-		foreach ( $response->getHeaders() as $name => $values ) {
53
-			foreach ( $values as $value ) {
54
-				header( sprintf( '%s: %s', $name, $value ), false );
52
+		foreach ($response->getHeaders() as $name => $values) {
53
+			foreach ($values as $value) {
54
+				header(sprintf('%s: %s', $name, $value), false);
55 55
 			}
56 56
 		}
57 57
 	}
@@ -62,27 +62,27 @@  discard block
 block discarded – undo
62 62
 	 * @param  ResponseInterface $response
63 63
 	 * @return null
64 64
 	 */
65
-	protected static function sendBody( $response, $chunk_size = 4096 ) {
65
+	protected static function sendBody($response, $chunk_size = 4096) {
66 66
 		$body = $response->getBody();
67
-		if ( $body->isSeekable() ) {
67
+		if ($body->isSeekable()) {
68 68
 			$body->rewind();
69 69
 		}
70 70
 
71
-		$content_length = $response->getHeaderLine( 'Content-Length' );
72
-		if ( ! $content_length ) {
71
+		$content_length = $response->getHeaderLine('Content-Length');
72
+		if ( ! $content_length) {
73 73
 			$content_length = $body->getSize();
74 74
 		}
75 75
 
76 76
 		$content_left = $content_length ? $content_length : -1;
77
-		$amount_to_read = $content_left > -1 ? min( $chunk_size, $content_left ) : $chunk_size;
78
-		while ( ! $body->eof() ) {
79
-			echo $body->read( $amount_to_read );
77
+		$amount_to_read = $content_left > -1 ? min($chunk_size, $content_left) : $chunk_size;
78
+		while ( ! $body->eof()) {
79
+			echo $body->read($amount_to_read);
80 80
 
81
-			if ( $content_left > -1 ) {
81
+			if ($content_left > -1) {
82 82
 				$content_left -= $amount_to_read;
83 83
 			}
84 84
 
85
-			if ( connection_status() != CONNECTION_NORMAL ) {
85
+			if (connection_status() != CONNECTION_NORMAL) {
86 86
 				break;
87 87
 			}
88 88
 		}
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	 * @param  string       $output
96 96
 	 * @return Psr7Response
97 97
 	 */
98
-	public static function output( Psr7Response $response, $output ) {
99
-		$response = $response->withBody( Psr7\stream_for( $output ) );
98
+	public static function output(Psr7Response $response, $output) {
99
+		$response = $response->withBody(Psr7\stream_for($output));
100 100
 		return $response;
101 101
 	}
102 102
 
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 	 * @param  array           $context
109 109
 	 * @return Psr7Response
110 110
 	 */
111
-	public static function template( Psr7Response $response, $templates, $context = array() ) {
112
-		$templates = is_array( $templates ) ? $templates : [$templates];
113
-		$template = locate_template( $templates, false );
111
+	public static function template(Psr7Response $response, $templates, $context = array()) {
112
+		$templates = is_array($templates) ? $templates : [$templates];
113
+		$template = locate_template($templates, false);
114 114
 
115
-		$engine = Framework::resolve( 'framework.templating.engine' );
116
-		$html = $engine->render( $template, $context );
115
+		$engine = Framework::resolve('framework.templating.engine');
116
+		$html = $engine->render($template, $context);
117 117
 
118
-		$response = $response->withHeader( 'Content-Type', 'text/html' );
119
-		$response = $response->withBody( Psr7\stream_for( $html ) );
118
+		$response = $response->withHeader('Content-Type', 'text/html');
119
+		$response = $response->withBody(Psr7\stream_for($html));
120 120
 		return $response;
121 121
 	}
122 122
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 * @param  array        $data
128 128
 	 * @return Psr7Response
129 129
 	 */
130
-	public static function json( Psr7Response $response, $data ) {
131
-		$response = $response->withHeader( 'Content-Type', 'application/json' );
132
-		$response = $response->withBody( Psr7\stream_for( wp_json_encode( $data ) ) );
130
+	public static function json(Psr7Response $response, $data) {
131
+		$response = $response->withHeader('Content-Type', 'application/json');
132
+		$response = $response->withBody(Psr7\stream_for(wp_json_encode($data)));
133 133
 		return $response;
134 134
 	}
135 135
 
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 * @param  integer      $status
142 142
 	 * @return Psr7Response
143 143
 	 */
144
-	public static function redirect( Psr7Response $response, $url, $status = 302 ) {
145
-		$response = $response->withStatus( $status );
146
-		$response = $response->withHeader( 'Location', $url );
144
+	public static function redirect(Psr7Response $response, $url, $status = 302) {
145
+		$response = $response->withStatus($status);
146
+		$response = $response->withHeader('Location', $url);
147 147
 		return $response;
148 148
 	}
149 149
 
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 	 * @param  integer      $status
155 155
 	 * @return Psr7Response
156 156
 	 */
157
-	public static function error( Psr7Response $response, $status ) {
157
+	public static function error(Psr7Response $response, $status) {
158 158
 		global $wp_query;
159
-		if ( $status === 404 ) {
159
+		if ($status === 404) {
160 160
 			$wp_query->set_404();
161 161
 		}
162 162
 
163
-		$response = $response->withStatus( $status );
164
-		return static::template( $response, array( $status . '.php', 'index.php' ) );
163
+		$response = $response->withStatus($status);
164
+		return static::template($response, array($status . '.php', 'index.php'));
165 165
 	}
166 166
 }
Please login to merge, or discard this patch.
src/Routing/Conditions/Url.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -43,38 +43,38 @@  discard block
 block discarded – undo
43 43
 	 * 
44 44
 	 * @param string $url
45 45
 	 */
46
-	public function __construct( $url ) {
47
-		$url = UrlUtility::addLeadingSlash( $url );
48
-		$url = UrlUtility::addTrailingSlash( $url );
46
+	public function __construct($url) {
47
+		$url = UrlUtility::addLeadingSlash($url);
48
+		$url = UrlUtility::addTrailingSlash($url);
49 49
 		$this->url = $url;
50 50
 	}
51 51
 
52 52
 	/**
53 53
 	 * {@inheritDoc}
54 54
 	 */
55
-	public function satisfied( Request $request ) {
56
-		$validation_regex = $this->getValidationRegex( $this->getUrl() );
57
-		$url = UrlUtility::getCurrentPath( $request );
58
-		return (bool) preg_match( $validation_regex, $url );
55
+	public function satisfied(Request $request) {
56
+		$validation_regex = $this->getValidationRegex($this->getUrl());
57
+		$url = UrlUtility::getCurrentPath($request);
58
+		return (bool) preg_match($validation_regex, $url);
59 59
 	}
60 60
 
61 61
 	/**
62 62
 	 * {@inheritDoc}
63 63
 	 */
64
-	public function getArguments( Request $request ) {
65
-		$validation_regex = $this->getValidationRegex( $this->getUrl() );
66
-		$url = UrlUtility::getCurrentPath( $request );
64
+	public function getArguments(Request $request) {
65
+		$validation_regex = $this->getValidationRegex($this->getUrl());
66
+		$url = UrlUtility::getCurrentPath($request);
67 67
 		$matches = [];
68
-		$success = preg_match( $validation_regex, $url, $matches );
68
+		$success = preg_match($validation_regex, $url, $matches);
69 69
 
70
-		if ( ! $success ) {
70
+		if ( ! $success) {
71 71
 			return []; // this should not normally happen
72 72
 		}
73 73
 
74 74
 		$arguments = [];
75
-		$parameter_names = $this->getParameterNames( $this->getUrl() );
76
-		foreach ( $parameter_names as $parameter_name ) {
77
-			$arguments[] = ! empty( $matches[ $parameter_name ] ) ? $matches[ $parameter_name ] : '';
75
+		$parameter_names = $this->getParameterNames($this->getUrl());
76
+		foreach ($parameter_names as $parameter_name) {
77
+			$arguments[] = ! empty($matches[$parameter_name]) ? $matches[$parameter_name] : '';
78 78
 		}
79 79
 		
80 80
 		return $arguments;
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	 * @param  Url $url
96 96
 	 * @return Url
97 97
 	 */
98
-	public function concatenate( Url $url ) {
99
-		return new static( UrlUtility::removeTrailingSlash( $this->getUrl() ) . $url->getUrl() );
98
+	public function concatenate(Url $url) {
99
+		return new static(UrlUtility::removeTrailingSlash($this->getUrl()) . $url->getUrl());
100 100
 	}
101 101
 
102 102
 	/**
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
 	 * @param  string   $url
106 106
 	 * @return string[]
107 107
 	 */
108
-	protected function getParameterNames( $url ) {
108
+	protected function getParameterNames($url) {
109 109
 		$matches = [];
110
-		preg_match_all( $this->url_regex, $url, $matches );
110
+		preg_match_all($this->url_regex, $url, $matches);
111 111
 		return $matches['name'];
112 112
 	}
113 113
 
@@ -118,29 +118,29 @@  discard block
 block discarded – undo
118 118
 	 * @param  boolean $wrap
119 119
 	 * @return string
120 120
 	 */
121
-	public function getValidationRegex( $url, $wrap = true ) {
121
+	public function getValidationRegex($url, $wrap = true) {
122 122
 		$parameters = [];
123 123
 		
124 124
 		// Replace all parameters with placeholders
125
-		$validation_regex = preg_replace_callback( $this->url_regex, function( $matches ) use ( &$parameters ) {
125
+		$validation_regex = preg_replace_callback($this->url_regex, function($matches) use (&$parameters) {
126 126
 			$name = $matches['name'];
127
-			$optional = ! empty( $matches['optional'] );
128
-			$regex = ! empty( $matches['regex'] ) ? $matches['regex'] : $this->parameter_regex;
127
+			$optional = ! empty($matches['optional']);
128
+			$regex = ! empty($matches['regex']) ? $matches['regex'] : $this->parameter_regex;
129 129
 			$replacement = '(?P<' . $name . '>' . $regex . ')';
130
-			if ( $optional ) {
130
+			if ($optional) {
131 131
 				$replacement .= '?';
132 132
 			}
133 133
 
134
-			$placeholder = '___placeholder_' . sha1( count( $parameters) . '_' . $replacement . '_' . uniqid() ) . '___';
135
-			$parameters[ $placeholder ] = $replacement;
134
+			$placeholder = '___placeholder_' . sha1(count($parameters) . '_' . $replacement . '_' . uniqid()) . '___';
135
+			$parameters[$placeholder] = $replacement;
136 136
 			return $placeholder;
137
-		}, $url );
137
+		}, $url);
138 138
 
139 139
 		// quote the remaining string so that it does not get evaluated as regex
140
-		$validation_regex = preg_quote( $validation_regex, '~' );
140
+		$validation_regex = preg_quote($validation_regex, '~');
141 141
 
142 142
 		// replace the placeholders with the real parameter regexes
143
-		$validation_regex = str_replace( array_keys( $parameters ), array_values( $parameters ), $validation_regex );
143
+		$validation_regex = str_replace(array_keys($parameters), array_values($parameters), $validation_regex);
144 144
 
145 145
 		// add a question mark to the end to make the trailing slash optional
146 146
 		$validation_regex = $validation_regex . '?';
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		// make sure the regex matches the entire url
149 149
 		$validation_regex = '^' . $validation_regex . '$';
150 150
 
151
-		if ( $wrap ) {
151
+		if ($wrap) {
152 152
 			$validation_regex = '~' . $validation_regex . '~';
153 153
 		}
154 154
 
Please login to merge, or discard this patch.
src/Url.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 	 * 
14 14
 	 * @return string
15 15
 	 */
16
-	public static function getCurrentPath( Request $request ) {
16
+	public static function getCurrentPath(Request $request) {
17 17
 		$url = $request->getUrl();
18
-		$relative_url = substr( $url, strlen( home_url( '/' ) ) );
19
-		$relative_url = static::addLeadingSlash( $relative_url );
20
-		$relative_url = preg_replace( '~\?.*~', '', $relative_url );
21
-		$relative_url = static::addTrailingSlash( $relative_url );
18
+		$relative_url = substr($url, strlen(home_url('/')));
19
+		$relative_url = static::addLeadingSlash($relative_url);
20
+		$relative_url = preg_replace('~\?.*~', '', $relative_url);
21
+		$relative_url = static::addTrailingSlash($relative_url);
22 22
 		return $relative_url;
23 23
 	}
24 24
 
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 	 * @param  string $url
29 29
 	 * @return string
30 30
 	 */
31
-	public static function addLeadingSlash( $url ) {
32
-		return '/' . static::removeLeadingSlash( $url );
31
+	public static function addLeadingSlash($url) {
32
+		return '/' . static::removeLeadingSlash($url);
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 	 * @param  string $url
39 39
 	 * @return string
40 40
 	 */
41
-	public static function removeLeadingSlash( $url ) {
42
-		return preg_replace( '/^\/+/', '', $url );
41
+	public static function removeLeadingSlash($url) {
42
+		return preg_replace('/^\/+/', '', $url);
43 43
 	}
44 44
 
45 45
 	/**
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	 * @param  string $url
49 49
 	 * @return string
50 50
 	 */
51
-	public static function addTrailingSlash( $url ) {
52
-		return trailingslashit( $url );
51
+	public static function addTrailingSlash($url) {
52
+		return trailingslashit($url);
53 53
 	}
54 54
 
55 55
 	/**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @param  string $url
59 59
 	 * @return string
60 60
 	 */
61
-	public static function removeTrailingSlash( $url ) {
62
-		return untrailingslashit( $url );
61
+	public static function removeTrailingSlash($url) {
62
+		return untrailingslashit($url);
63 63
 	}
64 64
 }
Please login to merge, or discard this patch.