Skip to content

Commit

Permalink
added phpstan config file, raised phpstan level to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Nov 18, 2022
1 parent 0f3b586 commit 5c85296
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -74,4 +74,4 @@ jobs:
run: composer install --no-interaction

- name: PHPStan
run: vendor/bin/phpstan analyse src/ tests/ --level=1
run: vendor/bin/phpstan analyse -c phpstan.neon
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
[![Total Downloads](https://img.shields.io/packagist/dt/heimrichhannot/contao-encore-bundle.svg)](https://packagist.org/packages/heimrichhannot/contao-encore-bundle)
![CI](https://github.com/heimrichhannot/contao-encore-bundle/workflows/CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/heimrichhannot/contao-encore-bundle/badge.svg?branch=master)](https://coveralls.io/github/heimrichhannot/contao-encore-bundle?branch=master)
![](https://img.shields.io/badge/PHPStan-level%201-brightgreen.svg?style=flat)
![](https://img.shields.io/badge/PHPStan-level%202-brightgreen.svg?style=flat)

Use the power and simplicity of symfony webpack encore in contao. This bundle let you decide on layout and page level, which encore entries should be loaded. If you want more, you can prepare your bundles define their own encore entries, so never need to manually add or remove encore entries again.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -45,7 +45,8 @@
"php-coveralls/php-coveralls": "^2.0",
"symfony/phpunit-bridge": "^3.2 || ^4.0 || ^5.0 || ^6.0",
"heimrichhannot/contao-test-utilities-bundle": "^0.1.4",
"phpstan/phpstan": "^1.8"
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-symfony": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon
@@ -0,0 +1,19 @@
parameters:
level: 2
paths:
- src
- tests
universalObjectCratesClasses:
- Contao\LayoutModel
- Contao\Model
- Contao\Template
- PHPUnit\Framework\MockObject\MockObject
ignoreErrors:
- message: '#^Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject\:\:setName\(\)\.$#'
path: tests/EventListener/Contao/ParseTemplateListenerTest.php
- message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:getChildNodeDefinitions\(\)\.$#'
path: tests/DependencyInjection/ConfigurationTest.php
- message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\NodeInterface\:\:getChildren\(\)\.$#'
path: tests/DependencyInjection/ConfigurationTest.php
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
8 changes: 5 additions & 3 deletions src/Asset/EntrypointsJsonLookup.php
Expand Up @@ -10,6 +10,7 @@

use Contao\LayoutModel;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;

/**
* @deprecated Use EntryCollection instead
Expand Down Expand Up @@ -39,9 +40,10 @@ public function __construct(array $bundleConfig, CacheItemPoolInterface $cache =
}

/**
* @param array $entrypointJsonFiles entrypoint json files
* @param array $bundleConfigEntries Entries defined by encore bundle config
* @param string|null $babelPolyfillEntryName entry name of babel polyfill
* @param array $entrypointJsonFiles entrypoint json files
* @param array $bundleConfigEntries Entries defined by encore bundle config
*
* @throws InvalidArgumentException
*/
public function mergeEntries(array $entrypointJsonFiles, array $bundleConfigEntries, LayoutModel $layout = null): array
{
Expand Down
7 changes: 4 additions & 3 deletions src/Collection/EntryCollection.php
Expand Up @@ -47,9 +47,10 @@ public function getEntries(): array
}

/**
* @param array $entrypointJsonFiles entrypoint json files
* @param array $bundleConfigEntries Entries defined by encore bundle config
* @param string|null $babelPolyfillEntryName entry name of babel polyfill
* @param array $entrypointJsonFiles entrypoint json files
* @param array $bundleConfigEntries Entries defined by encore bundle config
*
* @throws NoEntrypointsException
*/
private function mergeEntries(array $entrypointJsonFiles, array $bundleConfigEntries, LayoutModel $layout = null): array
{
Expand Down
20 changes: 3 additions & 17 deletions src/DependencyInjection/Configuration.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2021 Heimrich & Hannot GmbH
* Copyright (c) 2022 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand All @@ -17,14 +17,7 @@ public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('huh_encore');

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('huh_encore');
} else {
$rootNode = $treeBuilder->getRootNode();
}

$rootNode
$treeBuilder->getRootNode()
->children()
->booleanNode('use_contao_template_variables')
->defaultFalse()
Expand Down Expand Up @@ -110,14 +103,7 @@ public function getConfigTreeBuilder()
public function addLegacyNode()
{
$treeBuilder = new TreeBuilder('encore');

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$node = $treeBuilder->root('encore');
} else {
$node = $treeBuilder->getRootNode();
}

$node = $treeBuilder->getRootNode();
$node
->addDefaultsIfNotSet()
->setDeprecated('Configs within encore key are deprecated and will be removed in next major version.')
Expand Down
Expand Up @@ -66,10 +66,10 @@ public function __invoke(string $buffer): string

$pageModel->loadDetails();

/** @var LayoutModel|null $layout */
if (!($layout = $this->contaoFramework->getAdapter(LayoutModel::class)->findByPk(($pageModel->layoutId ?? $pageModel->layout)))) {
return $buffer;
}
/* @var LayoutModel|null $layout */

if (!isset($this->bundleConfig['use_contao_template_variables']) || true !== $this->bundleConfig['use_contao_template_variables']) {
$buffer = $this->replaceEncoreTags($buffer, $pageModel, $layout);
Expand Down
3 changes: 1 addition & 2 deletions src/Helper/ArrayHelper.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2021 Heimrich & Hannot GmbH
* Copyright (c) 2022 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand All @@ -15,7 +15,6 @@ class ArrayHelper
*
* @param $array
* @param $key
* @param bool $flip
*
* @return array
*/
Expand Down

0 comments on commit 5c85296

Please sign in to comment.