Skip to content

Commit 5b4f7a6

Browse files
committed
ADD PHPStan to the QA tools
1 parent 0e5840c commit 5b4f7a6

14 files changed

Lines changed: 99 additions & 42 deletions

.github/workflows/testing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ jobs:
3939
# Run tests suite
4040
- name: Run test suite
4141
run: php vendor/bin/simple-phpunit --coverage-text
42+
43+
# Run PHPStan
44+
- name: Run PHPStan
45+
run: php vendor/bin/phpstan

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9-
- support for **Symfony** v6
9+
- support for **Symfony** v6
10+
- **PHP CodeSniffer**, **PHP Compatibility**, **PHPStan** & **PHPStan strict rules** to the CI
1011

1112
## [2.0.0] - 2021-11-14
1213
### Changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"symfony/filesystem": "^5.1|^6.0",
3636
"squizlabs/php_codesniffer": "^3.6",
3737
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
38-
"phpcompatibility/php-compatibility": "^9.3"
38+
"phpcompatibility/php-compatibility": "^9.3",
39+
"phpstan/phpstan": "^1.2",
40+
"phpstan/extension-installer": "^1.1",
41+
"phpstan/phpstan-strict-rules": "^1.1"
3942
}
4043
}

phpstan.neon

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- src
5+
- tests
6+
bootstrapFiles:
7+
- vendor/bin/.phpunit/phpunit-9.5-0/vendor/autoload.php
8+
typeAliases:
9+
converterConfig: 'array{name: string, type: string, options: mixed[]|null, extensions: class-string[]}'
10+
ignoreErrors:
11+
-
12+
message: '~^Call to an undefined method [a-zA-Z0-9\\_]+::[a-zA-Z]+\(\).$~'
13+
path: src/DependencyInjection/Configuration.php
14+

src/AymdevCommonmarkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AymdevCommonmarkBundle extends Bundle
1414
/**
1515
* @codeCoverageIgnore
1616
*/
17-
public function build(ContainerBuilder $container)
17+
public function build(ContainerBuilder $container): void
1818
{
1919
parent::build($container);
2020

src/DependencyInjection/AymdevCommonmarkExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
class AymdevCommonmarkExtension extends Extension
1717
{
18-
public function load(array $configs, ContainerBuilder $container)
18+
/**
19+
* @param mixed[] $configs
20+
*/
21+
public function load(array $configs, ContainerBuilder $container): void
1922
{
2023
$configuration = new Configuration();
2124
$config = $this->processConfiguration($configuration, $configs);

src/DependencyInjection/Compiler/ConvertersPass.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class ConvertersPass implements CompilerPassInterface
1919
/** @var Reference[] converter service IDs */
2020
private array $converters = [];
2121

22-
public function process(ContainerBuilder $container)
22+
public function process(ContainerBuilder $container): void
2323
{
24+
/** @var converterConfig[] $converters */
2425
$converters = $container->getParameter(self::PARAMETER_CONVERTERS);
2526

2627
foreach ($converters as $name => $config) {
@@ -33,7 +34,10 @@ public function process(ContainerBuilder $container)
3334
$this->setupTwigExtension($container);
3435
}
3536

36-
private function registerConverters(array $converterConfig, ContainerBuilder $container): array
37+
/**
38+
* @param converterConfig $converterConfig
39+
*/
40+
private function registerConverters(array $converterConfig, ContainerBuilder $container): void
3741
{
3842
// Create environment definition
3943
$environment = new ChildDefinition('aymdev_commonmark.environment.' . $converterConfig['type']);
@@ -69,8 +73,6 @@ private function registerConverters(array $converterConfig, ContainerBuilder $co
6973

7074
// Save converter for later twig extension arguments setup
7175
$this->converters[$converterConfig['name']] = new Reference($converterConfig['name']);
72-
73-
return $converterConfig;
7476
}
7577

7678
private function setupTwigExtension(ContainerBuilder $container): void

src/Twig/CommonMarkExtension.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ public function getFilters(): array
3030

3131
public function convertMarkdown(?string $markdown, ?string $converterName = null): ?string
3232
{
33+
if (null === $markdown) {
34+
return null;
35+
}
36+
3337
// Single converter setup
3438
if ($converterName === null && count($this->serviceLocator->getProvidedServices()) === 1) {
35-
/** @var MarkdownConverter $converter */
3639
$converterName = array_key_first($this->serviceLocator->getProvidedServices());
40+
41+
/** @var MarkdownConverter $converter */
3742
$converter = $this->serviceLocator->get($converterName);
3843
return $converter->convertToHtml($markdown);
3944
}
4045

46+
if (null === $converterName) {
47+
return null;
48+
}
49+
4150
if (false === $this->serviceLocator->has($converterName)) {
4251
$message = 'The "%s" converter does not exists. Did you mean one of these ? %s';
4352
$availableConverters = implode(', ', array_keys($this->serviceLocator->getProvidedServices()));
4453
throw new \InvalidArgumentException(sprintf($message, $converterName, $availableConverters));
4554
}
4655

47-
if ($markdown === null) {
48-
return null;
49-
}
50-
5156
/** @var MarkdownConverter $converter */
5257
$converter = $this->serviceLocator->get($converterName);
5358
return $converter->convertToHtml($markdown)->getContent();

tests/AymdevCommonmarkBundleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
namespace Tests\AymDev\CommonMarkBundle;
44

55
use Aymdev\CommonmarkBundle\AymdevCommonmarkBundle;
6-
use Aymdev\CommonmarkBundle\DependencyInjection\AymdevCommonMarkExtension;
6+
use Aymdev\CommonmarkBundle\DependencyInjection\AymdevCommonmarkExtension;
77
use PHPUnit\Framework\TestCase;
88

99
class AymdevCommonmarkBundleTest extends TestCase
1010
{
1111
/**
1212
* Ensure the extension will be loaded
1313
*/
14-
public function testExtensionNameConsistency()
14+
public function testExtensionNameConsistency(): void
1515
{
1616
$bundle = new AymdevCommonmarkBundle();
1717
$extension = $bundle->getContainerExtension();
1818

19-
self::assertInstanceOf(AymdevCommonMarkExtension::class, $extension);
19+
self::assertInstanceOf(AymdevCommonmarkExtension::class, $extension);
2020
}
2121
}

tests/DependencyInjection/AymDevCommonmarkExtensionTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tests\AymDev\CommonMarkBundle\DependencyInjection;
44

5-
use Aymdev\CommonmarkBundle\DependencyInjection\AymdevCommonMarkExtension;
5+
use Aymdev\CommonmarkBundle\DependencyInjection\AymdevCommonmarkExtension;
66
use Aymdev\CommonmarkBundle\DependencyInjection\Compiler\ConvertersPass;
77
use League\CommonMark\Environment\Environment;
88
use League\CommonMark\MarkdownConverter;
@@ -14,10 +14,10 @@ class AymDevCommonmarkExtensionTest extends TestCase
1414
/**
1515
* Asserts that the converters configuration is saved as a container parameter
1616
*/
17-
public function testDefaultConfiguration()
17+
public function testDefaultConfiguration(): void
1818
{
1919
$container = new ContainerBuilder();
20-
$extension = new AymdevCommonMarkExtension();
20+
$extension = new AymdevCommonmarkExtension();
2121

2222
$extension->load([], $container);
2323
self::assertNotNull($container->getParameter(ConvertersPass::PARAMETER_CONVERTERS));
@@ -26,24 +26,27 @@ public function testDefaultConfiguration()
2626
/**
2727
* Asserts the default services are correctly defined
2828
*/
29-
public function testDefaultServicesRegistration()
29+
public function testDefaultServicesRegistration(): void
3030
{
3131
$container = new ContainerBuilder();
32-
$extension = new AymdevCommonMarkExtension();
32+
$extension = new AymdevCommonmarkExtension();
3333

3434
$extension->load([], $container);
3535

3636
// "empty" Environment
37+
/** @var Environment $emptyEnvironment */
3738
$emptyEnvironment = $container->get('aymdev_commonmark.environment.empty');
3839
self::assertInstanceOf(Environment::class, $emptyEnvironment);
3940
self::assertCount(0, $emptyEnvironment->getExtensions());
4041

4142
// CommonMark Environment
43+
/** @var Environment $commonMarkEnvironment */
4244
$commonMarkEnvironment = $container->get('aymdev_commonmark.environment.commonmark');
4345
self::assertInstanceOf(Environment::class, $commonMarkEnvironment);
4446
self::assertNotCount(0, $commonMarkEnvironment->getExtensions());
4547

4648
// GitHub Environment
49+
/** @var Environment $githubEnvironment */
4750
$githubEnvironment = $container->get('aymdev_commonmark.environment.github');
4851
self::assertInstanceOf(Environment::class, $githubEnvironment);
4952
self::assertNotCount(0, $githubEnvironment->getExtensions());

0 commit comments

Comments
 (0)