Skip to content

Commit

Permalink
extract methods
Browse files Browse the repository at this point in the history
  • Loading branch information
spiechu committed Jan 21, 2018
1 parent 97f6727 commit b1ec361
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/EventListener/GetMethodOverrideListener.php
Expand Up @@ -5,6 +5,7 @@
namespace Spiechu\SymfonyCommonsBundle\EventListener;

use Spiechu\SymfonyCommonsBundle\Utils\AssertUtils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class GetMethodOverrideListener
Expand Down Expand Up @@ -48,10 +49,18 @@ public function onKernelRequest(GetResponseEvent $getResponseEvent): void

$request = $getResponseEvent->getRequest();

if (!$request->isMethod('GET')) {
if (!$request->isMethod(Request::METHOD_GET)) {
return;
}

$this->overrideRequestMethod($request);
}

/**
* @param Request $request
*/
protected function overrideRequestMethod(Request $request): void
{
if (!$request->query->has($this->queryParamName)) {
return;
}
Expand Down
26 changes: 19 additions & 7 deletions src/Service/SchemaValidator/XmlSchemaValidator.php
Expand Up @@ -28,14 +28,9 @@ public function validate(string $xmlString): ValidationResult
libxml_clear_errors();

try {
$doc = new \DOMDocument();
$doc->preserveWhiteSpace = true;
$doc->formatOutput = true;
$doc->recover = true;
$document = $this->createDOMDocument($xmlString);

$doc->loadXML($xmlString);

if ($doc->schemaValidateSource(file_get_contents($this->schemaLocation))) {
if ($document->schemaValidateSource(file_get_contents($this->schemaLocation))) {
return $validationResult;
}

Expand All @@ -50,4 +45,21 @@ public function validate(string $xmlString): ValidationResult
libxml_use_internal_errors($useInternalErrors);
}
}

/**
* @param string $xmlString
*
* @return \DOMDocument
*/
protected function createDOMDocument(string $xmlString): \DOMDocument
{
$document = new \DOMDocument();
$document->preserveWhiteSpace = true;
$document->formatOutput = true;
$document->recover = true;

$document->loadXML($xmlString);

return $document;
}
}

0 comments on commit b1ec361

Please sign in to comment.