Skip to content

Commit

Permalink
php-cs-fixer and phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Apr 3, 2024
1 parent 315d435 commit 422f97d
Show file tree
Hide file tree
Showing 35 changed files with 145 additions and 72 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Static analysis

on:
push:
branches:
- '[0-9]+.x'
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.x'
pull_request:

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: "curl,dom,json,xml,dom"
coverage: none

- name: Checkout code
uses: actions/checkout@v3

# have to install phpstan ourselves here, the phpstan-ga fails at composer install with weird errors
- name: Install phpstan
run: |
composer require --no-update jackalope/jackalope-doctrine-dbal jackalope/jackalope-jackrabbit phpstan/phpstan
composer update
- name: PHPStan
run: vendor/bin/phpstan analyze --no-progress

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --dry-run --diff
10 changes: 1 addition & 9 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ jobs:
matrix:
include:
- php-version: "8.1"
phpunit-version: "9.5"
phpunit-flags: "-v --coverage-text"
symfony-version: "6.0.*"

- php-version: "8.1"
phpunit-version: "9.5"

- php-version: "8.2"
phpunit-version: "9.5"

- php-version: "8.3"
phpunit-version: "9.5"
symfony-version: "7.*"

steps:
Expand Down Expand Up @@ -65,8 +61,4 @@ jobs:
run: "tests/phpcr_odm_doctrine_dbal.sh"

- name: "Execute test cases"
run: |
if [[ $SYMFONY_PHPUNIT_VERSION == '' ]]; then unset SYMFONY_PHPUNIT_VERSION; fi;
vendor/bin/simple-phpunit ${{ matrix.phpunit-flags }}
env:
SYMFONY_PHPUNIT_VERSION: "${{ matrix.phpunit-version }}"
run: vendor/bin/phpunit ${{ matrix.phpunit-flags }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
composer.lock
vendor
phpunit.xml
!tests/Fixtures/App/var/.gitempty
tests/Fixtures/App/var
/.php_cs.cache
vendor
.phpunit.result.cache
.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->exclude(__DIR__.'/tests/Fixtures/App/var')
->name('*.php')
;

$config = new PhpCsFixer\Config();

return $config
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'single_line_throw' => false,
])
->setFinder($finder)
;
9 changes: 0 additions & 9 deletions .php_cs

This file was deleted.

8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@
"doctrine/orm": "^2.0 || ^3.0",
"jackalope/jackalope-doctrine-dbal": "^2.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0",
"phpcr/phpcr-shell": "^1.6",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^9.5",
"symfony/asset": "^5.4 || ^6.0 || ^7.0",
"symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
"symfony/css-selector": "^5.4 || ^6.0 || ^7.0",
"symfony/error-handler": "^5.4 || ^6.0 || ^7.0",
"symfony/form": "^5.4 || ^6.0 || ^7.0",
"symfony/monolog-bridge": "^5.4 || ^6.0 || ^7.0",
"symfony/monolog-bundle": "^3.4",
"symfony/phpunit-bridge": "^v6.4.2 || ^v7.0.2",
"symfony/stopwatch": "^5.4 || ^6.0 || ^7.0",
"symfony/templating": "^5.4 || ^6.0 || ^7.0",
"symfony/translation": "^5.4 || ^6.0 || ^7.0",
"symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0",
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-doctrine/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon
parameters:
level: 2
paths:
- src/
- tests/
excludePaths:
- tests/Fixtures/App/var/
- tests/Fixtures/fixtures/config/
- tests/Fixtures/App/config/
6 changes: 3 additions & 3 deletions src/Command/DoctrineCommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public static function setApplicationConnection(Application $application, string
{
$connectionService = sprintf('doctrine_phpcr.jackalope_doctrine_dbal.%s_connection', $sessionName);
$helperSet = $application->getHelperSet();
$helperSet->set(new DoctrineDBALHelper($application->getKernel()->getContainer()->get($connectionService)));
$helperSet->set(new DoctrineDbalHelper($application->getKernel()->getContainer()->get($connectionService)));
}

/**
* Prepare the DBAL connection and the PHPCR session.
*/
public static function setApplicationPHPCRSession(Application $application, string $sessionName = null, bool $admin = false): void
public static function setApplicationPHPCRSession(Application $application, ?string $sessionName = null, bool $admin = false): void
{
$registry = self::getRegistry($application);
$session = $admin ? $registry->getAdminConnection($sessionName) : $registry->getConnection($sessionName);
Expand All @@ -52,7 +52,7 @@ public static function setApplicationPHPCRSession(Application $application, stri
|| $session->getTransport() instanceof DbalLoggingClient
)
) {
$helperSet->set(new DoctrineDBALHelper($session->getTransport()->getConnection()));
$helperSet->set(new DoctrineDbalHelper($session->getTransport()->getConnection()));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Command/NodeDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Wrapper to use this command in the symfony console with multiple sessions.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/PhpcrShellCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$launchShell = empty($args);
$session = $this->getPhpcrSession();

// If no arguments supplied, launch the shell uwith the embedded application
// If no arguments supplied, launch the shell with the embedded application
if ($launchShell) {
$shell = PhpcrShell::createEmbeddedShell($session);
$exitCode = $shell->run();
Expand Down
6 changes: 2 additions & 4 deletions src/DataCollector/PHPCRDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(ManagerRegistryInterface $registry)
$this->managers = $registry->getManagerNames();
}

public function collect(Request $request, Response $response, \Throwable $exception = null): void
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
$this->collectInternal($request, $response);
}
Expand Down Expand Up @@ -114,8 +114,6 @@ private function sanitizeCall($call)
* The return value is an array with the sanitized value and a boolean
* indicating if the original value was kept (allowing to use the sanitized
* value to explain the call).
*
* @param mixed $var
*/
private function sanitizeParam($var): array
{
Expand Down Expand Up @@ -155,7 +153,7 @@ private function sanitizeParam($var): array
return [$var, true];
}

protected function collectInternal(Request $request, Response $response, \Throwable $exception = null): void
protected function collectInternal(Request $request, Response $response, ?\Throwable $exception = null): void
{
$calls = [];
foreach ($this->loggers as $name => $logger) {
Expand Down
2 changes: 1 addition & 1 deletion src/DataCollector/StopWatchLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(?Stopwatch $stopwatch = null)
$this->stopwatch = $stopwatch;
}

public function startCall($method, array $params = null, array $env = null): void
public function startCall($method, ?array $params = null, ?array $env = null): void
{
if (null !== $this->stopwatch) {
$this->stopwatch->start('doctrine_phpcr', 'doctrine_phpcr');
Expand Down
4 changes: 2 additions & 2 deletions src/DataFixtures/PHPCRExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ final class PHPCRExecutor extends BasePHPCRExecutor

public function __construct(
DocumentManagerInterface $dm,
PHPCRPurger $purger = null,
InitializerManager $initializerManager = null
?PHPCRPurger $purger = null,
?InitializerManager $initializerManager = null
) {
parent::__construct($dm, $purger);

Expand Down
8 changes: 4 additions & 4 deletions src/DependencyInjection/DoctrinePHPCRExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Doctrine\Bundle\PHPCRBundle\DependencyInjection;

use Jackalope\Tools\Console\Command\InitDoctrineDbalCommand as BaseInitDoctrineDbalCommand;
use Jackalope\Tools\Console\Command\JackrabbitCommand as BaseJackrabbitCommand;
use Doctrine\Bundle\PHPCRBundle\ManagerRegistryInterface;
use Doctrine\ODM\PHPCR\Document\Generic;
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Jackalope\Session;
use Jackalope\Tools\Console\Command\InitDoctrineDbalCommand as BaseInitDoctrineDbalCommand;
use Jackalope\Tools\Console\Command\JackrabbitCommand as BaseJackrabbitCommand;
use PHPCR\SessionInterface;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->loader->load('jackalope_doctrine_dbal-commands.xml');
}

// default values in case no odm is configured. the manager registry needs these variables to be defined.
// default values in case no odm is configured. the manager registry needs these variables to be defined.
// if odm is enabled, the parameters are overwritten later in the `loadOdm` section.
$container->setParameter('doctrine_phpcr.odm.document_managers', []);
$container->setParameter('doctrine_phpcr.odm.default_document_manager', '');
Expand Down Expand Up @@ -588,7 +588,7 @@ protected function getMappingObjectDefaultName(): string
return 'Document';
}

protected function getMappingResourceConfigDirectory(string $bundleDir = null): string
protected function getMappingResourceConfigDirectory(?string $bundleDir = null): string
{
return 'Resources/config/doctrine';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form/ChoiceList/PhpcrOdmQueryBuilderLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class PhpcrOdmQueryBuilderLoader implements EntityLoaderInterface
/**
* @param QueryBuilder|\Closure $queryBuilder
*/
public function __construct($queryBuilder, DocumentManagerInterface $manager = null, string $class = null)
public function __construct($queryBuilder, ?DocumentManagerInterface $manager = null, ?string $class = null)
{
// If a query builder was passed, it must be a closure or QueryBuilder
// instance
Expand Down
6 changes: 3 additions & 3 deletions src/Form/PhpcrOdmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function guessType(string $class, string $property): ?TypeGuess

case 'referrers':
return new TypeGuess(DocumentType::class, [
'class' => $mapping['referringDocument'],
'multiple' => true,
],
'class' => $mapping['referringDocument'],
'multiple' => true,
],
Guess::HIGH_CONFIDENCE
);

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/PHPCRReferenceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PHPCRReferenceType extends AbstractType
{
private ?SessionInterface $session;

public function __construct(SessionInterface $session = null)
public function __construct(?SessionInterface $session = null)
{
$this->session = $session;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Initializer/InitializerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ManagerRegistryInterface $registry)
$this->registry = $registry;
}

public function setLoggingClosure(\Closure $closure = null): void
public function setLoggingClosure(?\Closure $closure = null): void
{
$this->loggingClosure = $closure;
}
Expand All @@ -52,7 +52,7 @@ public function addInitializer(InitializerInterface $initializer, int $priority
/**
* Iterate over the registered initializers and execute each of them.
*/
public function initialize(string $sessionName = null): void
public function initialize(?string $sessionName = null): void
{
$loggingClosure = $this->loggingClosure;

Expand Down
4 changes: 2 additions & 2 deletions src/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Doctrine\ODM\PHPCR\PHPCRException;
use PHPCR\SessionInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Bridge\Doctrine\ManagerRegistry as BaseManagerRegistry;

/**
Expand All @@ -18,7 +18,7 @@ final class ManagerRegistry extends BaseManagerRegistry implements ManagerRegist
* @param string[] $entityManagers
*/
public function __construct(
ContainerInterface $container,
Container $container,
array $connections,
array $entityManagers,
string $defaultConnectionName,
Expand Down
1 change: 1 addition & 0 deletions src/OptionalCommand/Jackalope/JackrabbitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(
) {
parent::__construct(self::NAME);
}

protected function configure(): void
{
parent::configure();
Expand Down
3 changes: 1 addition & 2 deletions src/OptionalCommand/ODM/LoadFixtureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\PHPCRPurger;
use Doctrine\ODM\PHPCR\Tools\Console\Helper\DocumentManagerHelper;
use InvalidArgumentException;
use PHPCR\Util\Console\Command\BaseCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -117,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$fixtures = $loader->getFixtures();
if (!$fixtures) {
throw new InvalidArgumentException(
throw new \InvalidArgumentException(
sprintf('Could not find any fixtures to load in: %s', "\n\n- ".implode("\n- ", $paths))
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Test/RepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getRegistry(): ManagerRegistryInterface
return $this->managerRegistry;
}

public function getDocumentManager(string $managerName = null): DocumentManagerInterface
public function getDocumentManager(?string $managerName = null): DocumentManagerInterface
{
return $this->getRegistry()->getManager($managerName);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Validator/Constraints/ValidPhpcrOdmValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function __construct(ManagerRegistryInterface $registry)
*/
public function validate($document, Constraint $constraint): void
{
if (!$constraint instanceof ValidPhpcrOdm) {
throw new \InvalidArgumentException('Expected a constraint of class '.ValidPhpcrOdm::class);
}
$className = \get_class($document);
$dm = $this->registry->getManagerForClass($className);

Expand Down
Loading

0 comments on commit 422f97d

Please sign in to comment.