@@ -27,6 +27,9 @@ discard block |
||
| 27 | 27 | $this->strictMode = $strictMode; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | + /** |
|
| 31 | + * @param boolean $isIndex |
|
| 32 | + */ |
|
| 30 | 33 | private function getSchema($isIndex) |
| 31 | 34 | { |
| 32 | 35 | if ($isIndex) { |
@@ -40,6 +43,10 @@ discard block |
||
| 40 | 43 | } |
| 41 | 44 | } |
| 42 | 45 | |
| 46 | + /** |
|
| 47 | + * @param string $body |
|
| 48 | + * @param string $filename |
|
| 49 | + */ |
|
| 43 | 50 | private function validateBody($body, $filename, $isIndex = true) |
| 44 | 51 | { |
| 45 | 52 | $dom = new \DOMDocument(); |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | private function getSchema($isIndex) |
| 31 | 31 | { |
| 32 | 32 | if ($isIndex) { |
| 33 | - return __DIR__ . '/' . self::INDEX; |
|
| 33 | + return __DIR__.'/'.self::INDEX; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ($this->strictMode) { |
| 37 | - return __DIR__ . '/' . self::SCHEMA; |
|
| 37 | + return __DIR__.'/'.self::SCHEMA; |
|
| 38 | 38 | } else { |
| 39 | - return __DIR__ . '/' . self::NON_STRICT_SCHEMA; |
|
| 39 | + return __DIR__.'/'.self::NON_STRICT_SCHEMA; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
@@ -50,19 +50,19 @@ discard block |
||
| 50 | 50 | if (!$valid) { |
| 51 | 51 | $lastError = libxml_get_last_error(); |
| 52 | 52 | throw new ValidationFailedException( |
| 53 | - 'The given sitemap file (' . $filename . ') did not validate against the sitemap schema (last error: ' . str_replace("\n", '', $lastError->message) . ').'); |
|
| 53 | + 'The given sitemap file ('.$filename.') did not validate against the sitemap schema (last error: '.str_replace("\n", '', $lastError->message).').'); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | protected function doValidation(ResponseInterface $response) |
| 58 | 58 | { |
| 59 | - $body = (string)$response->getBody(); |
|
| 59 | + $body = (string) $response->getBody(); |
|
| 60 | 60 | |
| 61 | 61 | // sitemapindex or urlset |
| 62 | 62 | if (preg_match('/<sitemapindex/', $body)) { |
| 63 | - $this->validateBody($body, (string)$response->getUri()); |
|
| 63 | + $this->validateBody($body, (string) $response->getUri()); |
|
| 64 | 64 | } elseif (preg_match('/<urlset/', $body)) { |
| 65 | - $this->validateBody($body, (string)$response->getUri(), false); |
|
| 65 | + $this->validateBody($body, (string) $response->getUri(), false); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | private function getSchema() |
| 17 | 17 | { |
| 18 | - return __DIR__ . '/' . self::SCHEMA; |
|
| 18 | + return __DIR__.'/'.self::SCHEMA; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function validate(ResponseInterface $response) |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - $body = (string)$response->getBody(); |
|
| 27 | + $body = (string) $response->getBody(); |
|
| 28 | 28 | if (preg_match('/<rss/', $body)) { |
| 29 | 29 | libxml_clear_errors(); |
| 30 | 30 | $dom = new \DOMDocument(); |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | $lastError = libxml_get_last_error(); |
| 33 | 33 | if ($lastError) { |
| 34 | 34 | throw new ValidationFailedException( |
| 35 | - 'The given xml file is not well formed (last error: ' . |
|
| 36 | - str_replace("\n", '', $lastError->message) . ').'); |
|
| 35 | + 'The given xml file is not well formed (last error: '. |
|
| 36 | + str_replace("\n", '', $lastError->message).').'); |
|
| 37 | 37 | } |
| 38 | 38 | $valid = @$dom->schemaValidate($this->getSchema()); |
| 39 | 39 | if (!$valid) { |
| 40 | 40 | $lastError = libxml_get_last_error(); |
| 41 | 41 | $lastErrorMessage = str_replace("\n", '', $lastError->message); |
| 42 | 42 | throw new ValidationFailedException( |
| 43 | - 'The given xml file did not Validate vs. ' . |
|
| 44 | - $this->getSchema() . ' (last error: ' . |
|
| 45 | - $lastErrorMessage . ').'); |
|
| 43 | + 'The given xml file did not Validate vs. '. |
|
| 44 | + $this->getSchema().' (last error: '. |
|
| 45 | + $lastErrorMessage.').'); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | protected function doValidation(ResponseInterface $response) |
| 24 | 24 | { |
| 25 | - $body = (string)$response->getBody(); |
|
| 25 | + $body = (string) $response->getBody(); |
|
| 26 | 26 | |
| 27 | 27 | $dom = new \DOMDocument(); |
| 28 | 28 | @$dom->loadXML($body); |
| 29 | 29 | |
| 30 | - $filename = (string)$response->getUri(); |
|
| 30 | + $filename = (string) $response->getUri(); |
|
| 31 | 31 | |
| 32 | 32 | $error = false; |
| 33 | 33 | $messageParts = array(); |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | $error = true; |
| 40 | 40 | $lastError = libxml_get_last_error(); |
| 41 | 41 | |
| 42 | - $messageParts[] = $xsdFile['xsdfilename'] . ' - ' . $xsdFile['xsdfileurl'] . '(last error: ' . str_replace("\n", '', $lastError->message) . ').'; |
|
| 42 | + $messageParts[] = $xsdFile['xsdfilename'].' - '.$xsdFile['xsdfileurl'].'(last error: '.str_replace("\n", '', $lastError->message).').'; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ($error === true) { |
| 47 | - $message = 'XML file (' . $filename . ') does not validate against the following XSD files: ' . implode(', ', $messageParts); |
|
| 47 | + $message = 'XML file ('.$filename.') does not validate against the following XSD files: '.implode(', ', $messageParts); |
|
| 48 | 48 | throw new ValidationFailedException($message); |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - $crawler = new Crawler((string)$response->getBody()); |
|
| 21 | + $crawler = new Crawler((string) $response->getBody()); |
|
| 22 | 22 | |
| 23 | 23 | $idList = $crawler->filterXPath('//*[@id!=""]'); |
| 24 | 24 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | if (count($duplicatedIds) > 0) { |
| 38 | 38 | unset($duplicatedIds['']); |
| 39 | - throw new ValidationFailedException('Duplicate ids found (' . implode(', ', array_keys($duplicatedIds)) . ')'); |
|
| 39 | + throw new ValidationFailedException('Duplicate ids found ('.implode(', ', array_keys($duplicatedIds)).')'); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -26,9 +26,9 @@ |
||
| 26 | 26 | |
| 27 | 27 | public function doValidation(ResponseInterface $response) |
| 28 | 28 | { |
| 29 | - $result = json_decode((string)$response->getBody()); |
|
| 29 | + $result = json_decode((string) $response->getBody()); |
|
| 30 | 30 | if ($result === null) { |
| 31 | - throw new ValidationFailedException("The given JSON data can not be validated (last error: '" . $this->json_errors[json_last_error()] . "')."); |
|
| 31 | + throw new ValidationFailedException("The given JSON data can not be validated (last error: '".$this->json_errors[json_last_error()]."')."); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | public function doValidation(ResponseInterface $response) |
| 56 | 56 | { |
| 57 | - $body = (string)$response->getBody(); |
|
| 57 | + $body = (string) $response->getBody(); |
|
| 58 | 58 | |
| 59 | 59 | $json = json_decode($body); |
| 60 | 60 | |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | if ($jsonValue === false || (is_array($jsonValue) && empty($jsonValue))) { |
| 75 | 75 | $error = true; |
| 76 | - $noCorrectJsonPaths[] = $path['pattern'] . ' (JSON Path not found)'; |
|
| 76 | + $noCorrectJsonPaths[] = $path['pattern'].' (JSON Path not found)'; |
|
| 77 | 77 | } |
| 78 | 78 | if ($this->checkRelation($path['relation'], $path['value'], $count) === false) { |
| 79 | 79 | $error = true; |
| 80 | - $noCorrectJsonPaths[] = $path['pattern'] . ' (number of JSONPaths is not correct corresponding to the given relation/value)'; |
|
| 80 | + $noCorrectJsonPaths[] = $path['pattern'].' (number of JSONPaths is not correct corresponding to the given relation/value)'; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | if ($error === true) { |
| 85 | 85 | $allNoCorrectJsonPaths = implode('", "', $noCorrectJsonPaths); |
| 86 | - throw new ValidationFailedException('Disonances with JSON Paths "' . $allNoCorrectJsonPaths . '!'); |
|
| 86 | + throw new ValidationFailedException('Disonances with JSON Paths "'.$allNoCorrectJsonPaths.'!'); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | protected function doValidation(ResponseInterface $response) |
| 35 | 35 | { |
| 36 | - $data = json_decode((string)$response->getBody()); |
|
| 36 | + $data = json_decode((string) $response->getBody()); |
|
| 37 | 37 | if ($data === null) { |
| 38 | - throw new ValidationFailedException("The given JSON data can not be validated (last error: '" . $this->json_errors[json_last_error()] . "')."); |
|
| 38 | + throw new ValidationFailedException("The given JSON data can not be validated (last error: '".$this->json_errors[json_last_error()]."')."); |
|
| 39 | 39 | } else { |
| 40 | 40 | $errorStatus = false; |
| 41 | 41 | $messageParts = array(); |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | $errorStatus = true; |
| 52 | 52 | $errorMessage = ''; |
| 53 | 53 | foreach ($validator->getErrors() as $error) { |
| 54 | - $errorMessage = $errorMessage . sprintf("[%s] %s\n", $error['property'], $error['message']); |
|
| 54 | + $errorMessage = $errorMessage.sprintf("[%s] %s\n", $error['property'], $error['message']); |
|
| 55 | 55 | } |
| 56 | - $messageParts[] = $jsonSchemaFile['jsonfilename'] . ' - ' . $jsonSchemaFile['jsonfileurl'] . '(last error: ' . $errorMessage . ').'; |
|
| 56 | + $messageParts[] = $jsonSchemaFile['jsonfilename'].' - '.$jsonSchemaFile['jsonfileurl'].'(last error: '.$errorMessage.').'; |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if ($errorStatus === true) { |
| 61 | - $message = 'JSON file (' . (string) $response->getUri() . ') does not validate against the following JSON Schema files: ' . implode(', ', $messageParts); |
|
| 61 | + $message = 'JSON file ('.(string) $response->getUri().') does not validate against the following JSON Schema files: '.implode(', ', $messageParts); |
|
| 62 | 62 | throw new ValidationFailedException($message); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | protected function doValidation(ResponseInterface $response) |
| 28 | 28 | { |
| 29 | - $document = new Document((string)$response->getBody()); |
|
| 29 | + $document = new Document((string) $response->getBody()); |
|
| 30 | 30 | $images = $document->getImages($response->getUri()); |
| 31 | 31 | |
| 32 | 32 | $foreignImages = array(); |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | foreach ($images as $image) { |
| 38 | 38 | /* @var $image Uri */ |
| 39 | 39 | if ($currentUri->getHost($this->depth) !== $image->getHost($this->depth)) { |
| 40 | - $foreignImages[] = (string)$image; |
|
| 40 | + $foreignImages[] = (string) $image; |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $this->assert(count($foreignImages) === 0, 'Images from a foreign domain where found (' . implode(', ', $foreignImages) . ')'); |
|
| 44 | + $this->assert(count($foreignImages) === 0, 'Images from a foreign domain where found ('.implode(', ', $foreignImages).')'); |
|
| 45 | 45 | } |
| 46 | 46 | } |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | { |
| 17 | 17 | if ($response instanceof ContentTypeAwareResponse) { |
| 18 | 18 | if (($response->getStatusCode() < 300 || $response->getStatusCode() >= 400) && $response->getContentType() === 'text/html') { |
| 19 | - if (stripos((string)$response->getBody(), '</html>') === false) { |
|
| 20 | - throw new ValidationFailedException('Closing html tag is missing (document lengh: ' . strlen((string)$response->getBody()) . ').'); |
|
| 19 | + if (stripos((string) $response->getBody(), '</html>') === false) { |
|
| 20 | + throw new ValidationFailedException('Closing html tag is missing (document lengh: '.strlen((string) $response->getBody()).').'); |
|
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | } |