1- <?php // @codingStandardsIgnoreStart
2- // @codingStandardsIgnoreEnd
1+ <?php // @codingStandardsIgnoreLine
32namespace InterNations \Component \HttpMock ;
43
54use Exception ;
1413 __DIR__ . '/../vendor/autoload.php ' ,
1514 __DIR__ . '/../../../autoload.php ' ,
1615];
16+
1717$ autoloaderFound = false ;
18+
1819foreach ($ autoloadFiles as $ autoloadFile ) {
1920 if (file_exists ($ autoloadFile )) {
2021 require_once $ autoloadFile ;
2122 $ autoloaderFound = true ;
2223 break ;
2324 }
2425}
26+
2527if (!$ autoloaderFound ) {
2628 throw new RuntimeException (
2729 sprintf ('Could not locate autoloader file. Tried "%s" ' , implode ($ autoloadFiles , '", " ' ))
@@ -46,11 +48,13 @@ static function (Request $request) use ($app) {
4648 static function (Request $ request ) use ($ app ) {
4749
4850 $ matcher = [];
51+
4952 if ($ request ->request ->has ('matcher ' )) {
5053 $ matcher = Util::silentDeserialize ($ request ->request ->get ('matcher ' ));
5154 $ validator = static function ($ closure ) {
5255 return is_callable ($ closure );
5356 };
57+
5458 if (!is_array ($ matcher ) || count (array_filter ($ matcher , $ validator )) !== count ($ matcher )) {
5559 return new Response (
5660 'POST data key "matcher" must be a serialized list of closures ' ,
@@ -64,6 +68,7 @@ static function (Request $request) use ($app) {
6468 }
6569
6670 $ response = Util::silentDeserialize ($ request ->request ->get ('response ' ));
71+
6772 if (!$ response instanceof Response) {
6873 return new Response (
6974 'POST data key "response" must be a serialized Symfony response ' ,
@@ -72,8 +77,10 @@ static function (Request $request) use ($app) {
7277 }
7378
7479 $ limiter = null ;
80+
7581 if ($ request ->request ->has ('limiter ' )) {
7682 $ limiter = Util::silentDeserialize ($ request ->request ->get ('limiter ' ));
83+
7784 if (!is_callable ($ limiter )) {
7885 return new Response (
7986 'POST data key "limiter" must be a serialized closure ' ,
@@ -115,6 +122,7 @@ static function (Exception $e) use ($app) {
115122 $ notFoundResponse = new Response ('No matching expectation found ' , Response::HTTP_NOT_FOUND );
116123
117124 $ expectations = $ app ['storage ' ]->read ($ request , 'expectations ' );
125+
118126 foreach ($ expectations as $ pos => $ expectation ) {
119127 foreach ($ expectation ['matcher ' ] as $ matcher ) {
120128 if (!$ matcher ($ request )) {
@@ -137,6 +145,7 @@ static function (Exception $e) use ($app) {
137145 }
138146
139147 $ code = ($ e instanceof HttpException) ? $ e ->getStatusCode () : Response::HTTP_INTERNAL_SERVER_ERROR ;
148+
140149 return new Response ('Server error: ' . $ e ->getMessage (), $ code );
141150 }
142151);
@@ -152,6 +161,7 @@ static function (Request $request) use ($app) {
152161 '/_request/{index} ' ,
153162 static function (Request $ request , $ index ) use ($ app ) {
154163 $ requestData = $ app ['storage ' ]->read ($ request , 'requests ' );
164+
155165 if (!isset ($ requestData [$ index ])) {
156166 return new Response ('Index ' . $ index . ' not found ' , Response::HTTP_NOT_FOUND );
157167 }
@@ -167,6 +177,7 @@ static function (Request $request, $action) use ($app) {
167177 $ fn = 'array_ ' . ($ action === 'last ' ? 'pop ' : 'shift ' );
168178 $ requestString = $ fn ($ requestData );
169179 $ app ['storage ' ]->store ($ request , 'requests ' , $ requestData );
180+
170181 if (!$ requestString ) {
171182 return new Response ($ action . ' not possible ' , Response::HTTP_NOT_FOUND );
172183 }
@@ -181,6 +192,7 @@ static function (Request $request, $action) use ($app) {
181192 $ requestData = $ app ['storage ' ]->read ($ request , 'requests ' );
182193 $ fn = 'array_ ' . ($ action === 'last ' ? 'pop ' : 'shift ' );
183194 $ requestString = $ fn ($ requestData );
195+
184196 if (!$ requestString ) {
185197 return new Response ($ action . ' not available ' , Response::HTTP_NOT_FOUND );
186198 }
0 commit comments