From 72c9795ebe10288fa9684bb36e0b00f0e9932363 Mon Sep 17 00:00:00 2001 From: nnatter Date: Wed, 9 Oct 2019 13:07:19 +0200 Subject: [PATCH] Install and configure tooling (#14) * Remove styleci configuration, Add editorconfig file and php-cs-fixer configuration * Add license file * Install and configure phpstan with extensions * Add scripts to composer json, Execute phpstan in travis ci * automatically fixed coding style with pretty * Fix phpdoc in SetThemeEventListenerTest --- .editorconfig | 17 +++++++++++ .gitignore | 1 + .php_cs.dist | 28 +++++++++++++++++++ .styleci.yml | 13 --------- .travis.yml | 8 ++---- .../CompilerPass/ImageFormatCompilerPass.php | 12 ++++++-- .../WebspaceStructureProviderCompilerPass.php | 2 +- DependencyInjection/SuluThemeExtension.php | 2 +- EventListener/SetThemeEventListener.php | 6 ++-- LICENSE | 21 ++++++++++++++ .../WebspaceStructureProvider.php | 8 ++++-- SuluThemeBundle.php | 2 +- .../SetThemeEventListenerTest.php | 19 +++++++------ .../WebspaceStructureProviderTest.php | 8 +++--- composer.json | 20 +++++++++++-- phpstan.neon | 14 ++++++++++ 16 files changed, 138 insertions(+), 43 deletions(-) create mode 100644 .editorconfig create mode 100644 .php_cs.dist delete mode 100644 .styleci.yml create mode 100644 LICENSE create mode 100644 phpstan.neon diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..73a6c8d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 + +# markdown uses two trailing spaces for explicit line breaks +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 7cccf9a..fb8b535 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /composer.phar /composer.lock /.sass-cache/ +.php_cs.cache *~ # IDEs diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..0bf9e0c --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,28 @@ +exclude(['var/cache']) + ->in(__DIR__); + +return PhpCsFixer\Config::create() + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'class_definition' => false, + 'concat_space' => ['spacing' => 'one'], + 'function_declaration' => ['closure_function_spacing' => 'none'], + 'header_comment' => ['header' => $header], + 'ordered_imports' => true, + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_types_order' => false, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index b30d120..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,13 +0,0 @@ -preset: symfony - -enabled: - - concat_with_spaces - - ordered_use - - short_array_syntax - -disabled: - - concat_without_spaces - - phpdoc_align - - phpdoc_indent - - phpdoc_to_comment - - blankline_after_open_tag diff --git a/.travis.yml b/.travis.yml index 2de4ecc..020a397 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ matrix: - php: 7.3 env: - COMPOSER_FLAGS="--prefer-dist --no-interaction" + - PHPSTAN=true before_install: - echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini @@ -25,8 +26,5 @@ before_script: - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update $COMPOSER_FLAGS script: - - vendor/bin/phpunit - -notifications: - slack: - secure: "Gd3/1e0pBKvJv1UhWpBkWijJpmSWlarg6uPBJO0h4z1IpkZjd++jOjhmOQ7n+yMfuapQuJTcVOK0yIWu7orJoGAKFkBlMEIrLk1xMAG9phjjMLUO0FWgcQ3eVW5mTyfMBtClz4OL5wXckw17ohtXHDK8qnI0Hz9Qj8Rqgf2OZhM=" + - if [[ $PHPSTAN = true ]]; then composer phpstan; fi + - composer phpunit diff --git a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php index 9e63a67..67cbeca 100644 --- a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php +++ b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -11,6 +11,7 @@ namespace Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass; +use Liip\ThemeBundle\ActiveTheme; use Sulu\Bundle\MediaBundle\DependencyInjection\AbstractImageFormatCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -26,6 +27,7 @@ protected function getFiles(ContainerBuilder $container) { $files = []; + /** @var ActiveTheme $activeTheme */ $activeTheme = $container->get('liip_theme.active_theme'); $bundles = $container->getParameter('kernel.bundles'); $configPath = 'config/image-formats.xml'; @@ -33,9 +35,15 @@ protected function getFiles(ContainerBuilder $container) foreach ($activeTheme->getThemes() as $theme) { foreach ($bundles as $bundleName => $bundle) { $bundleReflection = new \ReflectionClass($bundle); + $fileName = $bundleReflection->getFileName(); + + if (!$fileName) { + continue; + } + $path = sprintf( '%s/Resources/themes/%s/%s', - dirname($bundleReflection->getFileName()), + dirname($fileName), $theme, $configPath ); diff --git a/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php b/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php index db35ca0..c60b655 100644 --- a/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php +++ b/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/DependencyInjection/SuluThemeExtension.php b/DependencyInjection/SuluThemeExtension.php index cfa13ae..c369ce4 100644 --- a/DependencyInjection/SuluThemeExtension.php +++ b/DependencyInjection/SuluThemeExtension.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/EventListener/SetThemeEventListener.php b/EventListener/SetThemeEventListener.php index d72aa26..d21bbd7 100644 --- a/EventListener/SetThemeEventListener.php +++ b/EventListener/SetThemeEventListener.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -38,7 +38,7 @@ public function __construct(ActiveTheme $activeTheme) * * @param GetResponseEvent $event */ - public function setActiveThemeOnRequest(GetResponseEvent $event) + public function setActiveThemeOnRequest(GetResponseEvent $event): void { if (null === ($attributes = $event->getRequest()->get('_sulu')) || null === ($webspace = $attributes->getAttribute('webspace')) @@ -55,7 +55,7 @@ public function setActiveThemeOnRequest(GetResponseEvent $event) * * @param PreRenderEvent $event */ - public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event) + public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event): void { $this->activeTheme->setName($event->getAttribute('webspace')->getTheme()); } diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ec76ef7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 MassiveArt Webservices GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/StructureProvider/WebspaceStructureProvider.php b/StructureProvider/WebspaceStructureProvider.php index c2ec427..34a5bb3 100644 --- a/StructureProvider/WebspaceStructureProvider.php +++ b/StructureProvider/WebspaceStructureProvider.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -61,14 +61,18 @@ protected function loadStructures($webspaceKey) $before = $this->activeTheme->getName(); $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); + if (!$webspace) { + return []; + } + if (null !== $webspace->getTheme()) { $this->activeTheme->setName($webspace->getTheme()); } $structures = []; $keys = []; + /** @var PageBridge $page */ foreach ($this->structureManager->getStructures() as $page) { - /* @var PageBridge $page */ $template = sprintf('%s.html.twig', $page->getView()); if ($this->templateExists($template)) { $keys[] = $page->getKey(); diff --git a/SuluThemeBundle.php b/SuluThemeBundle.php index 07d582b..23d332f 100644 --- a/SuluThemeBundle.php +++ b/SuluThemeBundle.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/Tests/Unit/EventListener/SetThemeEventListenerTest.php b/Tests/Unit/EventListener/SetThemeEventListenerTest.php index f2abe49..c1d38f6 100644 --- a/Tests/Unit/EventListener/SetThemeEventListenerTest.php +++ b/Tests/Unit/EventListener/SetThemeEventListenerTest.php @@ -1,8 +1,9 @@ listener = new SetThemeEventListener($this->activeTheme->reveal()); } - public function testEventListener() + public function testEventListener(): void { $request = $this->prophesize(Request::class); $attributes = $this->prophesize(RequestAttributes::class); @@ -67,7 +68,7 @@ public function testEventListener() $this->listener->setActiveThemeOnRequest($event->reveal()); } - public function testEventListenerNotMaster() + public function testEventListenerNotMaster(): void { $request = $this->prophesize(Request::class); $attributes = $this->prophesize(RequestAttributes::class); @@ -83,7 +84,7 @@ public function testEventListenerNotMaster() $this->listener->setActiveThemeOnRequest($event->reveal()); } - public function testEventListenerNoWebspace() + public function testEventListenerNoWebspace(): void { $request = $this->prophesize(Request::class); $attributes = $this->prophesize(RequestAttributes::class); @@ -99,7 +100,7 @@ public function testEventListenerNoWebspace() $this->listener->setActiveThemeOnRequest($event->reveal()); } - public function testEventListenerNoAttributes() + public function testEventListenerNoAttributes(): void { $request = $this->prophesize(Request::class); $request->get('_sulu')->willReturn(null); @@ -113,7 +114,7 @@ public function testEventListenerNoAttributes() $this->listener->setActiveThemeOnRequest($event->reveal()); } - public function testEventListenerOnPreview() + public function testEventListenerOnPreview(): void { $attributes = $this->prophesize(RequestAttributes::class); $attributes->getAttribute('webspace', null)->willReturn($this->webspace->reveal()); diff --git a/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php b/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php index 00a6f76..6411602 100644 --- a/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php +++ b/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php @@ -3,7 +3,7 @@ /* * This file is part of Sulu. * - * (c) MASSIVE ART WebServices GmbH + * (c) Sulu GmbH * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -18,7 +18,7 @@ class WebspaceStructureProviderTest extends TestCase { - public function testGetStructures() + public function testGetStructures(): void { $cache = new ArrayCache(); @@ -69,7 +69,7 @@ public function testGetStructures() $this->assertEquals(['t2'], $cache->fetch('sulu_io')); } - public function testGetStructuresCached() + public function testGetStructuresCached(): void { $cache = new ArrayCache(); $cache->save('sulu_io', ['t1', 't3']); @@ -118,7 +118,7 @@ public function testGetStructuresCached() * * @return StructureInterface */ - private function generateStructure($key, $view) + private function generateStructure(string $key, string $view): StructureInterface { $mock = $this->prophesize('Sulu\Component\Content\Compat\Structure\PageBridge'); diff --git a/composer.json b/composer.json index ea960b6..c1be09b 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,10 @@ "type": "sulu-bundle", "description": "The Sulu Bundle which provides themes", "license": "MIT", - "keywords": ["sulu", "theme"], + "keywords": [ + "sulu", + "theme" + ], "authors": [ { "name": "Sulu Community", @@ -19,7 +22,12 @@ "jackalope/jackalope-jackrabbit": "^1.3", "jackalope/jackalope-doctrine-dbal": "^1.3", "symfony/symfony": "^4.3", - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.0", + "jangregor/phpstan-prophecy": "^0.4.1", + "phpstan/phpstan": "^0.11.12", + "phpstan/phpstan-phpunit": "^0.11.2", + "phpstan/phpstan-symfony": "^0.11.6", + "thecodingmachine/phpstan-strict-rules": "^0.11.2" }, "conflict": { "liip/theme-bundle": "1.6.0" @@ -28,5 +36,13 @@ "psr-4": { "Sulu\\Bundle\\ThemeBundle\\": "" } + }, + "scripts": { + "phpstan": [ + "vendor/bin/phpstan analyse" + ], + "phpunit": [ + "vendor/bin/phpunit" + ] } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..6efbc67 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,14 @@ +includes: + - vendor/jangregor/phpstan-prophecy/src/extension.neon + - vendor/phpstan/phpstan-symfony/extension.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon + - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon + +parameters: + paths: + - . + level: max + excludes_analyse: + - %currentWorkingDirectory%/DependencyInjection/Configuration.php + - %currentWorkingDirectory%/vendor/*