Skip to content

Commit

Permalink
Fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sstok committed Nov 27, 2023
1 parent b81bf73 commit 55f8e6b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 26 deletions.
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property Rollerworks\\\\Component\\\\X509Validator\\\\CertificateValidator\\:\\:\\$now\\.$#"
count: 1
path: tests/CertificateValidatorTest.php
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- vendor/rollerscapes/standards/phpstan.neon
#- phpstan-baseline.neon
- phpstan-baseline.neon

parameters:
#reportUnmatchedIgnoredErrors: false
Expand All @@ -12,5 +12,6 @@ parameters:
- var/
- templates/
- translations/
- tests/TestLogger.php

#ignoreErrors:
2 changes: 2 additions & 0 deletions src/OCSPValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Rollerworks\Component\X509Validator\Violation\CertificateIsRevoked;
use Rollerworks\Component\X509Validator\Violation\UnprocessablePEM;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -64,6 +65,7 @@ public function __construct(
/**
* @param array<string, string> $caList
*
* @throws UnprocessablePEM
* @throws CertificateIsRevoked
*/
public function validateStatus(string $certificate, array $caList = []): void
Expand Down
2 changes: 1 addition & 1 deletion src/Violation/UnsupportedDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final class UnsupportedDomain extends Violation
{
private readonly string $requiredPattern;
/** @var array<int, string> */
/** @var array<array-key, string> */
private readonly array $supported;

public function __construct(string $requiredPattern, string ...$supported)
Expand Down
1 change: 1 addition & 0 deletions src/X509DataExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class X509DataExtractor
private ?string $hash = null;
private ?X509Info $fields = null;

/** @throws UnprocessablePEM */
public function extractRawData(string $contents, string $name = '', bool $withPublicKey = false): X509Info
{
$hash = hash('sha256', $contents);
Expand Down
2 changes: 1 addition & 1 deletion src/X509Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ final class X509Info
/** @var array<int, string> */
public readonly array $emails;
public readonly string $fingerprint;
/** @var array<string, mixed> */
public readonly string $pubKey;
public readonly string $signatureAlgorithm;
public readonly \DateTimeImmutable $validFrom;
Expand All @@ -40,6 +39,7 @@ final class X509Info
*/
public readonly array $allFields;

/** @param array<string, mixed> $fields */
public function __construct(array $fields)
{
$this->altDomains = $fields['_alt_domains'] ?? [];
Expand Down
8 changes: 4 additions & 4 deletions tests/CertificateValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*/
final class CertificateValidatorTest extends TestCase
{
private ?CertificateValidator $certificateValidator = null;
private ?PdpManager $pdpManager;
private CertificateValidator $certificateValidator;
private PdpManager $pdpManager;

protected function setUp(): void
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public function validate_certificate_is_actually_readable(): void
self::fail('Exception was expected.');
} catch (UnprocessablePEM $e) {
self::assertSame(['name' => ''], $e->getParameters());
self::assertSame($certContents, $e->getPrevious()->getPrevious()->getMessage());
self::assertSame($certContents, $e->getPrevious()?->getPrevious()?->getMessage());
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ public function validate_certificate_data_is_readable(): void

self::fail('Exception was expected.');
} catch (UnprocessablePEM $e) {
self::assertSame($certContents, $e->getPrevious()->getPrevious()->getMessage());
self::assertSame($certContents, $e->getPrevious()?->getPrevious()?->getMessage());
self::assertSame([
'name' => '',
], $e->getParameters());
Expand Down
22 changes: 3 additions & 19 deletions tests/OCSPValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Rollerworks\Component\PdbSfBridge\PdpMockProvider;
use Rollerworks\Component\X509Validator\OCSPValidator;
use Rollerworks\Component\X509Validator\TranslatableArgument;
use Rollerworks\Component\X509Validator\Violation\CertificateIsRevoked;
use Rollerworks\Component\X509Validator\Violation\UnprocessablePEM;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\ErrorHandler\BufferingLogger;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\MockHttpClient;
Expand All @@ -41,27 +38,14 @@ final class OCSPValidatorTest extends TestCase
{
use ProphecyTrait;

private ?OCSPValidator $certificateValidator = null;
private static ?Psr16Cache $cache;

public static function setUpBeforeClass(): void
{
self::$cache = new Psr16Cache(new ArrayAdapter());
}

public static function tearDownAfterClass(): void
{
self::$cache = null;
}
private OCSPValidator $certificateValidator;

protected function setUp(): void
{
/** @var HttpClientInterface&LoggerAwareInterface $httpClient */
$httpClient = HttpClient::create();
$httpClient->setLogger(new BufferingLogger());

$this->pdpManager = PdpMockProvider::getPdpManager();

$this->certificateValidator = new OCSPValidator(
httpClient: $httpClient,
logger: $this->expectNoFailureLogs(),
Expand All @@ -84,7 +68,7 @@ public function validate_certificate_is_actually_readable(): void
self::fail('Exception was expected.');
} catch (UnprocessablePEM $e) {
self::assertSame(['name' => ''], $e->getParameters());
self::assertSame($certContents, $e->getPrevious()->getPrevious()->getMessage());
self::assertSame($certContents, $e->getPrevious()?->getPrevious()?->getMessage());
}
}

Expand All @@ -103,7 +87,7 @@ public function validate_certificate_data_is_readable(): void

self::fail('Exception was expected.');
} catch (UnprocessablePEM $e) {
self::assertSame($certContents, $e->getPrevious()->getPrevious()->getMessage());
self::assertSame($certContents, $e->getPrevious()?->getPrevious()?->getMessage());
self::assertSame([
'name' => '',
], $e->getParameters());
Expand Down

0 comments on commit 55f8e6b

Please sign in to comment.