Skip to content

Commit

Permalink
Update codacy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Aug 28, 2024
1 parent 11da71d commit d98e55f
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Classes/Middleware/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

$content = file_get_contents($parameters['url']);

Check warning on line 88 in Classes/Middleware/Validation.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Middleware/Validation.php#L88

The use of function file_get_contents() is discouraged
if ($content === false) {
throw new InvalidArgumentException('Error while loading content of "' . $parameters['url'] . '"' , 1724420640);
throw new InvalidArgumentException('Error while loading content of "' . $parameters['url'] . '"', 1724420640);

Check failure on line 90 in Classes/Middleware/Validation.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Middleware/Validation.php#L90

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$parameters['url']'.
}

$document = new DOMDocument();
Expand Down
5 changes: 2 additions & 3 deletions Classes/Validation/AbstractDlfValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Kitodo\Dlf\Validation;

use TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException;
use InvalidArgumentException;
use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator;

/**
Expand All @@ -32,7 +32,6 @@ abstract class AbstractDlfValidator extends AbstractValidator

/**
* @param $valueClassName string The class name of the value
* @throws InvalidValidationOptionsException
*/
public function __construct(string $valueClassName)
{
Expand All @@ -43,7 +42,7 @@ public function __construct(string $valueClassName)
public function validate($value)
{
if (!$value instanceof $this->valueClassName) {
throw new \InvalidArgumentException('Value must be an instance of ' . $this->valueClassName . '.', 1723126505626);
throw new InvalidArgumentException('Value must be an instance of ' . $this->valueClassName . '.', 1723126505626);

Check failure on line 45 in Classes/Validation/AbstractDlfValidator.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Validation/AbstractDlfValidator.php#L45

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$this'.
}
return parent::validate($value);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Validation/DOMDocumentValidationStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Kitodo\Dlf\Validation;

/**
* Implementation of BaseValidationStack for validating DOMDocument against the configured validators.
* Implementation of AbstractDlfValidationStack for validating DOMDocument against the configured validators.
*
* @package TYPO3
* @subpackage dlf
Expand Down
5 changes: 2 additions & 3 deletions Classes/Validation/LibXmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* LICENSE.txt file that was distributed with this source code.
*/

trait LibXmlTrait {

trait LibXmlTrait
{
/**
* Add the errors from the libxml error buffer as validation error.
*
Expand All @@ -41,5 +41,4 @@ public function disableErrorBuffer(): void
{
libxml_use_internal_errors(false);
}

}
3 changes: 2 additions & 1 deletion Classes/Validation/SaxonXslToSvrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
*
* @access public
*/
class SaxonXslToSvrlValidator extends AbstractDlfValidator {
class SaxonXslToSvrlValidator extends AbstractDlfValidator
{

private string $jar;

Expand Down
8 changes: 4 additions & 4 deletions Documentation/Developers/Validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Validators
DOMDocumentValidationStack
--------------------------

``Kitodo\Dlf\Validation\DOMDocumentValidationStack`` implementation of ``Kitodo\Dlf\Validation\BaseValidationStack`` for validating DOMDocument against the configurable validators.
``Kitodo\Dlf\Validation\DOMDocumentValidationStack`` implementation of ``Kitodo\Dlf\Validation\AbstractDlfValidationStack`` for validating DOMDocument against the configurable validators.

The configuration is an array validator configurations each with following entries:

Expand Down Expand Up @@ -128,13 +128,13 @@ Following fields are necessary for binding validator or validation stack to the
:description: Description

- :field: className
:description: Fully qualified class name of validator class derived from ``Kitodo\Dlf\Validation\BaseValidator`` or of validation stack class derived from ``Kitodo\Dlf\Validation\BaseValidationStack``
:description: Fully qualified class name of validator class derived from ``Kitodo\Dlf\Validation\AbstractDlfValidator`` or of validation stack class derived from ``Kitodo\Dlf\Validation\AbstractDlfValidationStack``

- :field: configuration
:description: Block of specific configuration of validator. (Only for validator class derived from ``Kitodo\Dlf\Validation\BaseValidator``)
:description: Block of specific configuration of validator. (Only for validator class derived from ``Kitodo\Dlf\Validation\AbstractDlfValidator``)

- :field: validators
:description: Blocks of validators or nested validation stacks. (Only for validation stack class derived from ``Kitodo\Dlf\Validation\BaseValidationStack``)
:description: Blocks of validators or nested validation stacks. (Only for validation stack class derived from ``Kitodo\Dlf\Validation\AbstractDlfValidationStack``)


TypoScript Example
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Validation/DOMDocumentValidationStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
* Testing BaseValidatorStack with implementation of DOMDocumentValidationStack.
* Testing AbstractDlfValidatorStack with implementation of DOMDocumentValidationStack.
*
* @package TYPO3
* @subpackage dlf
Expand Down Expand Up @@ -57,7 +57,7 @@ public function testValidatorClassNotExists(): void
public function testValidatorDerivation(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("TYPO3\CMS\Extbase\Validation\Validator\UrlValidator must be an instance of BaseValidator.");
$this->expectExceptionMessage("TYPO3\CMS\Extbase\Validation\Validator\UrlValidator must be an instance of AbstractDlfValidator.");
new DOMDocumentValidationStack([["className" => UrlValidator::class]]);
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/Validation/XmlSchemesValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Kitodo\Dlf\Tests\Unit\Validation;

use DOMDocument;
use Kitodo\Dlf\Validation\XmlSchemesValidator;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

Expand Down Expand Up @@ -74,7 +75,7 @@ public function testValidation(): void
["namespace" => "http://www.loc.gov/mods/v3", "schemaLocation" => "http://www.loc.gov/standards/mods/mods.xsd"]
]);

Check notice on line 76 in Tests/Unit/Validation/XmlSchemesValidatorTest.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Tests/Unit/Validation/XmlSchemesValidatorTest.php#L76

Closing parenthesis of a multi-line function call must be on a line by itself

$domDocument = new \DOMDocument();
$domDocument = new DOMDocument();
// Test with empty document
$result = $xmlSchemesValidator->validate($domDocument);
self::assertCount(1, $result->getErrors());
Expand Down

0 comments on commit d98e55f

Please sign in to comment.