From da790a7d42cf03864121f3bab7e973ae63317f46 Mon Sep 17 00:00:00 2001 From: dantleech Date: Wed, 3 Jun 2015 09:44:26 +0200 Subject: [PATCH] CS Fix --- .php_cs | 1 + bin/testconsole.php | 5 ++- lib/Collection/ReferrerCollection.php | 2 +- lib/DocumentInspector.php | 2 +- lib/Event/CreateEvent.php | 1 + lib/Event/FindEvent.php | 3 +- lib/Event/QueryCreateBuilderEvent.php | 1 + lib/NodeManager.php | 2 +- lib/PathBuilder.php | 16 ++++++++-- lib/Query/Query.php | 1 + lib/Strategy/MixinStrategy.php | 6 ++-- .../Behavior/Audit/BlameSubscriber.php | 2 +- .../Behavior/Path/AutoNameSubscriber.php | 3 +- lib/Subscriber/Phpcr/RemoveSubscriber.php | 2 -- lib/Subscriber/Phpcr/ReorderSubscriber.php | 2 +- symfony-di/core.xml | 2 -- tests/Bench/BaseBench.php | 7 ++-- tests/Bench/BenchmarkBench.php | 11 +++---- tests/Bench/PathBuilderBench.php | 7 ++-- tests/Bootstrap.php | 25 ++++++--------- tests/Functional/BaseTestCase.php | 7 ++-- tests/Functional/DocumentManager/FindTest.php | 9 +++--- tests/Functional/Model/FullDocument.php | 17 +++++----- tests/Unit/NodeManagerTest.php | 2 +- tests/Unit/PathBuilderTest.php | 32 +++++++++---------- 25 files changed, 81 insertions(+), 87 deletions(-) diff --git a/.php_cs b/.php_cs index df90ede..8a1e979 100644 --- a/.php_cs +++ b/.php_cs @@ -19,6 +19,7 @@ return Symfony\CS\Config\Config::create() '-concat_without_spaces', '-phpdoc_indent', '-phpdoc_params', + '-psr0', )) ->finder( Symfony\CS\Finder\DefaultFinder::create() diff --git a/bin/testconsole.php b/bin/testconsole.php index 83e1900..0d9995c 100755 --- a/bin/testconsole.php +++ b/bin/testconsole.php @@ -1,13 +1,12 @@ new \Jackalope\Tools\Console\Helper\DoctrineDbalHelper(Bootstrap::createDbalConnection()) + 'connection' => new \Jackalope\Tools\Console\Helper\DoctrineDbalHelper(Bootstrap::createDbalConnection()), )); $cli = new Application('Sulu Document Manager Test CLI', '0.1'); diff --git a/lib/Collection/ReferrerCollection.php b/lib/Collection/ReferrerCollection.php index 3f3be50..d4d794c 100644 --- a/lib/Collection/ReferrerCollection.php +++ b/lib/Collection/ReferrerCollection.php @@ -79,7 +79,7 @@ protected function initialize() // initialized, but if we don't do this, we won't know how many items are in the // collection, as one node could have many referring properties. foreach ($references as $reference) { - /** @var PropertyInterface $reference */ + /* @var PropertyInterface $reference */ $referrerNode = $reference->getParent(); $this->documents[$referrerNode->getIdentifier()] = $referrerNode; } diff --git a/lib/DocumentInspector.php b/lib/DocumentInspector.php index a0e82d8..adaec74 100644 --- a/lib/DocumentInspector.php +++ b/lib/DocumentInspector.php @@ -61,7 +61,7 @@ public function getParent($document) $parentNode = $this->getNode($document)->getParent(); if (!$parentNode) { - return null; + return; } return $this->proxyFactory->createProxyForNode($document, $parentNode); diff --git a/lib/Event/CreateEvent.php b/lib/Event/CreateEvent.php index 4cc6960..d478ebb 100644 --- a/lib/Event/CreateEvent.php +++ b/lib/Event/CreateEvent.php @@ -33,6 +33,7 @@ public function __construct($alias) /** * @return object + * * @throws \RuntimeException */ public function getDocument() diff --git a/lib/Event/FindEvent.php b/lib/Event/FindEvent.php index d86e78b..aad32d2 100644 --- a/lib/Event/FindEvent.php +++ b/lib/Event/FindEvent.php @@ -56,7 +56,7 @@ public function getDebugMessage() 'i:%s d:%s l:%s', $this->identifier, $this->document ? spl_object_hash($this->document) : '', - $this->locale ? : '' + $this->locale ?: '' ); } @@ -78,6 +78,7 @@ public function getLocale() /** * @return object + * * @throws DocumentManagerException */ public function getDocument() diff --git a/lib/Event/QueryCreateBuilderEvent.php b/lib/Event/QueryCreateBuilderEvent.php index 6799125..83a6d0a 100644 --- a/lib/Event/QueryCreateBuilderEvent.php +++ b/lib/Event/QueryCreateBuilderEvent.php @@ -31,6 +31,7 @@ public function setQueryBuilder(QueryBuilder $queryBuilder) /** * @return mixed + * * @throws DocumentManagerException */ public function getQueryBuilder() diff --git a/lib/NodeManager.php b/lib/NodeManager.php index 9540069..4478161 100644 --- a/lib/NodeManager.php +++ b/lib/NodeManager.php @@ -14,9 +14,9 @@ use PHPCR\NodeInterface; use PHPCR\RepositoryException; use PHPCR\SessionInterface; +use PHPCR\Util\NodeHelper; use PHPCR\Util\UUIDHelper; use Sulu\Component\DocumentManager\Exception\DocumentNotFoundException; -use PHPCR\Util\NodeHelper; /** * The node manager is responsible for talking to the PHPCR diff --git a/lib/PathBuilder.php b/lib/PathBuilder.php index fdb0f16..d23b43b 100644 --- a/lib/PathBuilder.php +++ b/lib/PathBuilder.php @@ -1,9 +1,18 @@ hasProperty('jcr:mixinTypes')) { - return null; + return; } - $mixinTypes = (array)$node->getPropertyValue('jcr:mixinTypes'); + $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes'); foreach ($mixinTypes as $mixinType) { if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) { @@ -65,6 +65,6 @@ public function resolveMetadataForNode(NodeInterface $node) } } - return null; + return; } } diff --git a/lib/Subscriber/Behavior/Audit/BlameSubscriber.php b/lib/Subscriber/Behavior/Audit/BlameSubscriber.php index b01e376..7baaa64 100644 --- a/lib/Subscriber/Behavior/Audit/BlameSubscriber.php +++ b/lib/Subscriber/Behavior/Audit/BlameSubscriber.php @@ -115,7 +115,7 @@ private function getUserId(array $options) $token = $this->tokenStorage->getToken(); if (null === $token || $token instanceof AnonymousToken) { - return null; + return; } $user = $token->getUser(); diff --git a/lib/Subscriber/Behavior/Path/AutoNameSubscriber.php b/lib/Subscriber/Behavior/Path/AutoNameSubscriber.php index 8c68ac3..95726c0 100644 --- a/lib/Subscriber/Behavior/Path/AutoNameSubscriber.php +++ b/lib/Subscriber/Behavior/Path/AutoNameSubscriber.php @@ -24,7 +24,6 @@ use Sulu\Component\DocumentManager\NameResolver; use Sulu\Component\DocumentManager\NodeManager; use Symfony\Cmf\Bundle\CoreBundle\Slugifier\SlugifierInterface; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -164,7 +163,7 @@ public function handlePersist(PersistEvent $event) */ private function rename(NodeInterface $node, $name) { - $names = (array)$node->getParent()->getNodeNames(); + $names = (array) $node->getParent()->getNodeNames(); $pos = array_search($node->getName(), $names); $next = isset($names[$pos + 1]) ? $names[$pos + 1] : null; diff --git a/lib/Subscriber/Phpcr/RemoveSubscriber.php b/lib/Subscriber/Phpcr/RemoveSubscriber.php index 7b01993..b21eb8b 100644 --- a/lib/Subscriber/Phpcr/RemoveSubscriber.php +++ b/lib/Subscriber/Phpcr/RemoveSubscriber.php @@ -11,8 +11,6 @@ namespace Sulu\Component\DocumentManager\Subscriber\Phpcr; -use PHPCR\NodeInterface; -use PHPCR\PropertyInterface; use Sulu\Component\DocumentManager\DocumentRegistry; use Sulu\Component\DocumentManager\Event\RemoveEvent; use Sulu\Component\DocumentManager\Events; diff --git a/lib/Subscriber/Phpcr/ReorderSubscriber.php b/lib/Subscriber/Phpcr/ReorderSubscriber.php index 26c1155..52eaf00 100644 --- a/lib/Subscriber/Phpcr/ReorderSubscriber.php +++ b/lib/Subscriber/Phpcr/ReorderSubscriber.php @@ -84,7 +84,7 @@ public function handleReorder(ReorderEvent $event) private function resolveSiblingName($siblingId, NodeInterface $parentNode, NodeInterface $node) { if (null === $siblingId) { - return null; + return; } $siblingPath = $siblingId; diff --git a/symfony-di/core.xml b/symfony-di/core.xml index 20f983d..4792c66 100644 --- a/symfony-di/core.xml +++ b/symfony-di/core.xml @@ -83,5 +83,3 @@ - - diff --git a/tests/Bench/BaseBench.php b/tests/Bench/BaseBench.php index fd65950..654aaf4 100644 --- a/tests/Bench/BaseBench.php +++ b/tests/Bench/BaseBench.php @@ -11,17 +11,14 @@ namespace Sulu\Component\DocumentManager\Tests\Bench; -use Sulu\Component\DocumentManager\Tests\Bootstrap; -use Sulu\Component\DocumentManager\Subscriber\Behavior; -use Symfony\Component\EventDispatcher\EventDispatcher; use PhpBench\Benchmark; +use Sulu\Component\DocumentManager\Tests\Bootstrap; abstract class BaseBench implements Benchmark { const BASE_NAME = 'test'; const BASE_PATH = '/test'; - private $session; private $container; protected function initPhpcr() @@ -50,6 +47,7 @@ protected function getContainer() protected function getSession() { $session = $this->getContainer()->get('doctrine_phpcr.default_session'); + return $session; } @@ -58,4 +56,3 @@ protected function getDocumentManager() return $this->getContainer()->get('sulu_document_manager.document_manager'); } } - diff --git a/tests/Bench/BenchmarkBench.php b/tests/Bench/BenchmarkBench.php index 1a95c23..e952dfe 100644 --- a/tests/Bench/BenchmarkBench.php +++ b/tests/Bench/BenchmarkBench.php @@ -11,7 +11,6 @@ namespace Sulu\Component\DocumentManager\Tests\Bench; -use PhpBench\BenchCase; use PhpBench\Benchmark\Iteration; class BenchmarkBench extends BaseBench @@ -37,7 +36,7 @@ public function benchCreatePersist(Iteration $iteration) $document = $manager->create('full'); foreach ($locales as $locale) { $manager->persist($document, $locale, array( - 'path' => self::BASE_PATH . '/node-' . $i + 'path' => self::BASE_PATH . '/node-' . $i, )); } } @@ -61,8 +60,8 @@ public function benchCreatePersistPhpcr(Iteration $iteration) $node = $baseNode->addNode('node-' . $i); foreach ($iteration->getParameter('locales') as $locale) { $node->addMixin('mix:test'); - $node->setProperty('lsys:' . $locale .'-created', new \DateTime()); - $node->setProperty('lsys:' . $locale .'-changed', new \DateTime()); + $node->setProperty('lsys:' . $locale . '-created', new \DateTime()); + $node->setProperty('lsys:' . $locale . '-changed', new \DateTime()); } } @@ -76,10 +75,10 @@ public function provideNodeTotals() 'nb_nodes' => 1, ), array( - 'nb_nodes' => 10, + 'nb_nodes' => 10, ), array( - 'nb_nodes' => 100, + 'nb_nodes' => 100, ), ); } diff --git a/tests/Bench/PathBuilderBench.php b/tests/Bench/PathBuilderBench.php index bc8b738..9997e3c 100644 --- a/tests/Bench/PathBuilderBench.php +++ b/tests/Bench/PathBuilderBench.php @@ -1,10 +1,10 @@ array('one', 'two', 'three') + 'elements' => array('one', 'two', 'three'), ), array( 'elements' => array('%one', '%two%', 'three'), ), ); } - } diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 8e9ba75..4cadec2 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -9,19 +9,16 @@ * with this source code in the file LICENSE. */ -namespace Sulu\Component\DocumentManager\Tests; +namespace Sulu\Component\DocumentManager\tests; use Jackalope\RepositoryFactoryDoctrineDBAL; +use Monolog\Handler\StreamHandler; +use Monolog\Logger; use PHPCR\SessionInterface; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; -use Sulu\Component\DocumentManager\EventDispatcher\DebugEventDispatcher; -use Symfony\Component\Stopwatch\Stopwatch; -use Monolog\Handler\StreamHandler; -use Monolog\Logger; class Bootstrap { @@ -35,21 +32,19 @@ public static function createContainer() $container = new ContainerBuilder(); $container->set('doctrine_phpcr.default_session', self::createSession()); - $stopwatch = new Stopwatch(); $logger = new Logger('test'); - $logger->pushHandler(new StreamHandler($logDir .'/test.log')); + $logger->pushHandler(new StreamHandler($logDir . '/test.log')); - //$dispatcher = new DebugEventDispatcher($container, $stopwatch, $logger); $dispatcher = new ContainerAwareEventDispatcher($container); $container->set('sulu_document_manager.event_dispatcher', $dispatcher); $config = array( 'sulu_document_manager.default_locale' => 'en', - 'sulu_document_manager.mapping'=> array( + 'sulu_document_manager.mapping' => array( 'full' => array( 'alias' => 'full', 'phpcr_type' => 'mix:test', - 'class' => 'Sulu\Component\DocumentManager\Tests\Functional\Model\FullDocument' + 'class' => 'Sulu\Component\DocumentManager\Tests\Functional\Model\FullDocument', ), ), 'sulu_document_manager.namespace_mapping' => array( @@ -77,13 +72,13 @@ public static function createContainer() } /** - * Create a new PHPCR session + * Create a new PHPCR session. * * @return SessionInterface */ public static function createSession() { - $transportName = getenv('SULU_DM_TRANSPORT') ? : 'jackalope-doctrine-dbal'; + $transportName = getenv('SULU_DM_TRANSPORT') ?: 'jackalope-doctrine-dbal'; switch ($transportName) { case 'jackalope-doctrine-dbal': @@ -104,7 +99,7 @@ public static function createDbalConnection() 'host' => 'localhost', 'user' => 'admin', 'password' => 'admin', - 'path' => __DIR__ . '/../data/test.sqlite' + 'path' => __DIR__ . '/../data/test.sqlite', )); return $connection; diff --git a/tests/Functional/BaseTestCase.php b/tests/Functional/BaseTestCase.php index 64463e3..8f73771 100644 --- a/tests/Functional/BaseTestCase.php +++ b/tests/Functional/BaseTestCase.php @@ -9,11 +9,9 @@ * with this source code in the file LICENSE. */ -namespace Sulu\Component\DocumentManager\Tests\Functional; +namespace Sulu\Component\DocumentManager\tests\Functional; use Sulu\Component\DocumentManager\Tests\Bootstrap; -use Sulu\Component\DocumentManager\Subscriber\Behavior; -use Symfony\Component\EventDispatcher\EventDispatcher; abstract class BaseTestCase extends \PHPUnit_Framework_TestCase { @@ -59,9 +57,8 @@ protected function generateDataSet(array $options) foreach ($options['locales'] as $locale) { $manager->persist($document, $locale, array( - 'path' => self::BASE_PATH + 'path' => self::BASE_PATH, )); } } } - diff --git a/tests/Functional/DocumentManager/FindTest.php b/tests/Functional/DocumentManager/FindTest.php index b37209f..a78c00d 100644 --- a/tests/Functional/DocumentManager/FindTest.php +++ b/tests/Functional/DocumentManager/FindTest.php @@ -9,12 +9,11 @@ * with this source code in the file LICENSE. */ -namespace Sulu\Component\DocumentManager\Tests\Functional\DocumentManager; +namespace Sulu\Component\DocumentManager\tests\Functional\DocumentManager; use Sulu\Component\DocumentManager\Tests\Functional\BaseTestCase; -use Sulu\Component\DocumentManager\Tests\Functional\Model\FullDocument; -class DocumentManagerTest extends BaseTestCase +class FindTest extends BaseTestCase { public function setUp() { @@ -22,7 +21,7 @@ public function setUp() } /** - * Persist a document in a single locale + * Persist a document in a single locale. */ public function testPersist() { @@ -38,7 +37,7 @@ public function testPersist() } /** - * Persist a document in a many locales + * Persist a document in a many locales. */ public function testPersistManyLocales() { diff --git a/tests/Functional/Model/FullDocument.php b/tests/Functional/Model/FullDocument.php index 17f60a4..28c9aa6 100644 --- a/tests/Functional/Model/FullDocument.php +++ b/tests/Functional/Model/FullDocument.php @@ -1,4 +1,5 @@ nodeName; } @@ -56,7 +57,7 @@ public function getNodeName() /** * {@inheritDoc} */ - public function getCreated() + public function getCreated() { return $this->created; } @@ -64,7 +65,7 @@ public function getCreated() /** * {@inheritDoc} */ - public function getChanged() + public function getChanged() { return $this->changed; } @@ -72,7 +73,7 @@ public function getChanged() /** * {@inheritDoc} */ - public function getCreator() + public function getCreator() { return $this->creator; } @@ -80,7 +81,7 @@ public function getCreator() /** * {@inheritDoc} */ - public function getChanger() + public function getChanger() { return $this->changer; } @@ -88,7 +89,7 @@ public function getChanger() /** * {@inheritDoc} */ - public function getParent() + public function getParent() { return $this->parent; } @@ -104,7 +105,7 @@ public function setParent($parent) /** * {@inheritDoc} */ - public function getUuid() + public function getUuid() { return $this->uuid; } @@ -128,7 +129,7 @@ public function getChildren() /** * {@inheritDoc} */ - public function getPath() + public function getPath() { return $this->path; } diff --git a/tests/Unit/NodeManagerTest.php b/tests/Unit/NodeManagerTest.php index 9fd10a4..1b10439 100644 --- a/tests/Unit/NodeManagerTest.php +++ b/tests/Unit/NodeManagerTest.php @@ -129,7 +129,7 @@ public function testClear() } /** - * It should purge the workspace + * It should purge the workspace. */ public function testPurgeWorkspace() { diff --git a/tests/Unit/PathBuilderTest.php b/tests/Unit/PathBuilderTest.php index 23fa563..f6df97a 100644 --- a/tests/Unit/PathBuilderTest.php +++ b/tests/Unit/PathBuilderTest.php @@ -1,10 +1,10 @@ pathBuilder = new PathBuilder($pathRegistry); } - /** - * @description Build path 1000 times - * @revs 1000 - * @beforeMethod setUp - */ - public function benchBuild() - { - $this->pathBuilder->build(array('%one%', '%two%', 'four')); - } - /** * It should build a path - * Using a combination of tokens and literal values + * Using a combination of tokens and literal values. */ public function testBuild() { @@ -40,7 +30,7 @@ public function testBuild() } /** - * It should build "/" for an empty array + * It should build "/" for an empty array. */ public function testBuildEmpty() { @@ -48,7 +38,7 @@ public function testBuildEmpty() } /** - * It should build "/" for an array with "/" + * It should build "/" for an array with "/". */ public function testBuildSingleSlash() { @@ -56,10 +46,18 @@ public function testBuildSingleSlash() } /** - * It should replace "//" with "/" + * It should replace "//" with "/". */ public function testBuildNoDoubleSlash() { $this->assertEquals('/hello/world', $this->pathBuilder->build(array('hello', '', '', 'world'))); } + + /** + * It should allow sub paths. + */ + public function testBuildSubPath() + { + $this->assertEquals('/hello/world/goodbye/world/k', $this->pathBuilder->build(array('hello', 'world/goodbye/world', 'k'))); + } }