Skip to content

Commit

Permalink
Install and configure tooling (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
niklasnatter authored and alexander-schranz committed Oct 9, 2019
1 parent 05772dd commit 72c9795
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 43 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/composer.phar
/composer.lock
/.sass-cache/
.php_cs.cache
*~

# IDEs
Expand Down
28 changes: 28 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$header = <<<EOF
This file is part of Sulu.
(c) Sulu GmbH
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

$finder = PhpCsFixer\Finder::create()
->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);
13 changes: 0 additions & 13 deletions .styleci.yml

This file was deleted.

8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
12 changes: 10 additions & 2 deletions DependencyInjection/CompilerPass/ImageFormatCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
/*
* 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.
*/

namespace Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass;

use Liip\ThemeBundle\ActiveTheme;
use Sulu\Bundle\MediaBundle\DependencyInjection\AbstractImageFormatCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -26,16 +27,23 @@ 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';

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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/SuluThemeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions EventListener/SetThemeEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'))
Expand All @@ -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());
}
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions StructureProvider/WebspaceStructureProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion SuluThemeBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 10 additions & 9 deletions Tests/Unit/EventListener/SetThemeEventListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/*
* 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.
Expand All @@ -12,18 +13,18 @@

use Liip\ThemeBundle\ActiveTheme;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\PreviewBundle\Preview\Events\PreRenderEvent;
use Sulu\Bundle\ThemeBundle\EventListener\SetThemeEventListener;
use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes;
use Sulu\Component\Webspace\Theme;
use Sulu\Component\Webspace\Webspace;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class SetThemeEventListenerTest extends TestCase
{
/**
* @var ActiveTheme
* @var ObjectProphecy|ActiveTheme
*/
private $activeTheme;

Expand All @@ -33,7 +34,7 @@ class SetThemeEventListenerTest extends TestCase
private $theme = 'test';

/**
* @var Webspace
* @var ObjectProphecy|Webspace
*/
private $webspace;

Expand All @@ -51,7 +52,7 @@ public function setUp(): void
$this->listener = new SetThemeEventListener($this->activeTheme->reveal());
}

public function testEventListener()
public function testEventListener(): void
{
$request = $this->prophesize(Request::class);
$attributes = $this->prophesize(RequestAttributes::class);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,7 +18,7 @@

class WebspaceStructureProviderTest extends TestCase
{
public function testGetStructures()
public function testGetStructures(): void
{
$cache = new ArrayCache();

Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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');

Expand Down
20 changes: 18 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -28,5 +36,13 @@
"psr-4": {
"Sulu\\Bundle\\ThemeBundle\\": ""
}
},
"scripts": {
"phpstan": [
"vendor/bin/phpstan analyse"
],
"phpunit": [
"vendor/bin/phpunit"
]
}
}
Loading

0 comments on commit 72c9795

Please sign in to comment.