From e35ca69fcff7bfa56dce236962add42760e16300 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Fri, 9 Mar 2018 08:23:35 -0300 Subject: [PATCH] [CS] Start to fix excluded ones - Remove alias functions, as well forbidden ones - Remove assignments in if condition --- lib/Doctrine/ODM/MongoDB/DocumentManager.php | 10 +++++++--- lib/Doctrine/ODM/MongoDB/DocumentRepository.php | 7 +++++-- lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | 3 +-- lib/Doctrine/ODM/MongoDB/MongoDBException.php | 4 ++-- .../DefaultPersistentCollectionGenerator.php | 6 +++--- .../ODM/MongoDB/Persisters/DocumentPersister.php | 6 ++++-- .../ODM/MongoDB/Persisters/PersistenceBuilder.php | 5 ++--- lib/Doctrine/ODM/MongoDB/SchemaManager.php | 4 +++- .../Tools/Console/Command/GenerateHydratorsCommand.php | 3 ++- .../Command/GeneratePersistentCollectionsCommand.php | 3 ++- .../Tools/Console/Command/GenerateProxiesCommand.php | 3 ++- .../ODM/MongoDB/Tools/Console/Command/QueryCommand.php | 6 ++++-- phpcs.xml.dist | 3 --- tests/Documents/Ecommerce/ConfigurableProduct.php | 3 ++- tests/bootstrap.php | 4 +++- tools/sandbox/config.php | 4 +++- 16 files changed, 45 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index aeb19137ba..b39b615ab4 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -143,7 +143,9 @@ protected function __construct(?Client $client = null, ?Configuration $config = $this->metadataFactory = new $metadataFactoryClassName(); $this->metadataFactory->setDocumentManager($this); $this->metadataFactory->setConfiguration($this->config); - if ($cacheDriver = $this->config->getMetadataCacheImpl()) { + + $cacheDriver = $this->config->getMetadataCacheImpl(); + if ($cacheDriver) { $this->metadataFactory->setCacheDriver($cacheDriver); } @@ -536,9 +538,10 @@ public function getReference($documentName, $identifier) { /* @var $class \Doctrine\ODM\MongoDB\Mapping\ClassMetadata */ $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\')); + $document = $this->unitOfWork->tryGetById($identifier, $class); // Check identity map first, if its already in there just return it. - if ($document = $this->unitOfWork->tryGetById($identifier, $class)) { + if ($document) { return $document; } @@ -570,9 +573,10 @@ public function getReference($documentName, $identifier) public function getPartialReference($documentName, $identifier) { $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\')); + $document = $this->unitOfWork->tryGetById($identifier, $class); // Check identity map first, if its already in there just return it. - if ($document = $this->unitOfWork->tryGetById($identifier, $class)) { + if ($document) { return $document; } $document = $class->newInstance(); diff --git a/lib/Doctrine/ODM/MongoDB/DocumentRepository.php b/lib/Doctrine/ODM/MongoDB/DocumentRepository.php index d41825be08..293ab40e20 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentRepository.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentRepository.php @@ -116,7 +116,8 @@ public function find($id, $lockMode = LockMode::NONE, $lockVersion = null) } // Check identity map first - if ($document = $this->uow->tryGetById($id, $this->class)) { + $document = $this->uow->tryGetById($id, $this->class); + if ($document) { if ($lockMode !== LockMode::NONE) { $this->dm->lock($document, $lockMode, $lockVersion); } @@ -134,7 +135,9 @@ public function find($id, $lockMode = LockMode::NONE, $lockVersion = null) if (! $this->class->isVersioned) { throw LockException::notVersioned($this->documentName); } - if ($document = $this->getDocumentPersister()->load($criteria)) { + + $document = $this->getDocumentPersister()->load($criteria); + if ($document) { $this->uow->lock($document, $lockMode, $lockVersion); } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index 97af1b7f32..805f0fecee 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -26,7 +26,6 @@ use function get_class; use function in_array; use function is_array; -use function is_null; use function is_string; use function is_subclass_of; use function ltrim; @@ -888,7 +887,7 @@ public function hasIndexes() */ public function setShardKey(array $keys, array $options = []) { - if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && ! is_null($this->shardKey)) { + if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && $this->shardKey !== null) { throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName()); } diff --git a/lib/Doctrine/ODM/MongoDB/MongoDBException.php b/lib/Doctrine/ODM/MongoDB/MongoDBException.php index fec82574fe..709b510612 100644 --- a/lib/Doctrine/ODM/MongoDB/MongoDBException.php +++ b/lib/Doctrine/ODM/MongoDB/MongoDBException.php @@ -7,9 +7,9 @@ use function array_slice; use function end; use function get_class; +use function implode; use function is_array; use function is_object; -use function join; use function sprintf; /** @@ -90,7 +90,7 @@ public static function invalidValueForType($type, $expected, $got) if (is_array($expected)) { $expected = sprintf( '%s or %s', - join(', ', array_slice($expected, 0, -1)), + implode(', ', array_slice($expected, 0, -1)), end($expected) ); } diff --git a/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php b/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php index cf93965ff0..c4aab45aa9 100644 --- a/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php +++ b/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php @@ -17,7 +17,6 @@ use function interface_exists; use function is_dir; use function is_writable; -use function join; use function method_exists; use function mkdir; use function rename; @@ -115,7 +114,7 @@ private function generateCollectionClass($for, $targetFqcn, $fileName) { $exploded = explode('\\', $targetFqcn); $class = array_pop($exploded); - $namespace = join('\\', $exploded); + $namespace = implode('\\', $exploded); $code = <<getParameterType($param); - if ($parameterType = $this->getParameterType($param)) { + if ($parameterType) { $parameterDefinition .= $parameterType . ' '; } diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index c394b60f86..94eac8d069 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -999,7 +999,8 @@ public function addFilterToPreparedQuery(array $preparedQuery) * @todo Consider recursive merging in case the filter criteria and * prepared query both contain top-level $and/$or operators. */ - if ($filterCriteria = $this->dm->getFilterCollection()->getFilterCriteria($this->class)) { + $filterCriteria = $this->dm->getFilterCollection()->getFilterCriteria($this->class); + if ($filterCriteria) { $preparedQuery = $this->cm->merge($preparedQuery, $this->prepareQueryOrNewObj($filterCriteria)); } @@ -1344,7 +1345,8 @@ private function getClassDiscriminatorValues(ClassMetadata $metadata) { $discriminatorValues = [$metadata->discriminatorValue]; foreach ($metadata->subClasses as $className) { - if ($key = array_search($className, $metadata->discriminatorMap)) { + $key = array_search($className, $metadata->discriminatorMap); + if ($key) { $discriminatorValues[] = $key; } } diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php b/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php index 0dbd45ad70..0ad9bd8342 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php @@ -13,7 +13,6 @@ use function array_search; use function array_values; use function get_class; -use function is_null; /** * PersistenceBuilder builds the queries used by the persisters to update and insert @@ -186,7 +185,7 @@ public function prepareUpdateData($document) // @ReferenceOne } elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) { if (isset($new) || $mapping['nullable'] === true) { - $updateData['$set'][$mapping['name']] = (is_null($new) ? null : $this->prepareReferencedDocumentValue($mapping, $new)); + $updateData['$set'][$mapping['name']] = ($new === null ? null : $this->prepareReferencedDocumentValue($mapping, $new)); } else { $updateData['$unset'][$mapping['name']] = true; } @@ -257,7 +256,7 @@ public function prepareUpsertData($document) // @ReferenceOne } elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) { if (isset($new) || $mapping['nullable'] === true) { - $updateData['$set'][$mapping['name']] = (is_null($new) ? null : $this->prepareReferencedDocumentValue($mapping, $new)); + $updateData['$set'][$mapping['name']] = ($new === null ? null : $this->prepareReferencedDocumentValue($mapping, $new)); } // @ReferenceMany, @EmbedMany diff --git a/lib/Doctrine/ODM/MongoDB/SchemaManager.php b/lib/Doctrine/ODM/MongoDB/SchemaManager.php index 5290d81263..b0fb1439dd 100644 --- a/lib/Doctrine/ODM/MongoDB/SchemaManager.php +++ b/lib/Doctrine/ODM/MongoDB/SchemaManager.php @@ -229,7 +229,9 @@ public function ensureDocumentIndexes($documentName, $timeout = null) if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) { throw new \InvalidArgumentException('Cannot create document indexes for mapped super classes, embedded documents or query result documents.'); } - if ($indexes = $this->getDocumentIndexes($documentName)) { + + $indexes = $this->getDocumentIndexes($documentName); + if ($indexes) { $collection = $this->dm->getDocumentCollection($class->name); foreach ($indexes as $index) { $keys = $index['keys']; diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateHydratorsCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateHydratorsCommand.php index cb52181060..d2e22d5a5d 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateHydratorsCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateHydratorsCommand.php @@ -59,9 +59,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $metadatas = $dm->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); + $destPath = $input->getArgument('dest-path'); // Process destination directory - if (($destPath = $input->getArgument('dest-path')) === null) { + if ($destPath === null) { $destPath = $dm->getConfiguration()->getHydratorDir(); } diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GeneratePersistentCollectionsCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GeneratePersistentCollectionsCommand.php index 48b90f7776..480ee2dbf0 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GeneratePersistentCollectionsCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GeneratePersistentCollectionsCommand.php @@ -59,9 +59,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $metadatas = $dm->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); + $destPath = $input->getArgument('dest-path'); // Process destination directory - if (($destPath = $input->getArgument('dest-path')) === null) { + if ($destPath === null) { $destPath = $dm->getConfiguration()->getPersistentCollectionDir(); } diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateProxiesCommand.php index 043c3ba7a1..3dd59c9412 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/GenerateProxiesCommand.php @@ -63,9 +63,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return ! $classMetadata->isEmbeddedDocument && ! $classMetadata->isMappedSuperclass && ! $classMetadata->isQueryResultDocument; }); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); + $destPath = $input->getArgument('dest-path'); // Process destination directory - if (($destPath = $input->getArgument('dest-path')) === null) { + if ($destPath === null) { $destPath = $dm->getConfiguration()->getProxyDir(); } diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php index f4372b6919..8cb2315599 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php @@ -84,7 +84,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O throw new \LogicException("Option 'depth' must contain an integer value"); } - if (($skip = $input->getOption('skip')) !== null) { + $skip = $input->getOption('skip'); + if ($skip !== null) { if (! is_numeric($skip)) { throw new \LogicException("Option 'skip' must contain an integer value"); } @@ -92,7 +93,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $qb->skip((int) $skip); } - if (($limit = $input->getOption('limit')) !== null) { + $limit = $input->getOption('limit'); + if ($limit !== null) { if (! is_numeric($limit)) { throw new \LogicException("Option 'limit' must contain an integer value"); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 3b6f7c2d61..6bb65288e3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -42,13 +42,10 @@ - - - diff --git a/tests/Documents/Ecommerce/ConfigurableProduct.php b/tests/Documents/Ecommerce/ConfigurableProduct.php index b898152287..124fd5bbd7 100644 --- a/tests/Documents/Ecommerce/ConfigurableProduct.php +++ b/tests/Documents/Ecommerce/ConfigurableProduct.php @@ -93,7 +93,8 @@ public function getOption($name) public function removeOption($name) { - if (($option = $this->_findOption($name)) === null) { + $option = $this->_findOption($name); + if ($option === null) { throw new \InvalidArgumentException('option ' . $name . ' doesn\'t exist'); } if ($this->options instanceof Collection) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4483540f04..49f2bfadea 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,7 +4,9 @@ use Doctrine\Common\Annotations\AnnotationRegistry; -if (! file_exists($file = __DIR__ . '/../vendor/autoload.php')) { +$file = __DIR__ . '/../vendor/autoload.php'; + +if (! file_exists($file)) { throw new RuntimeException('Install dependencies to run test suite.'); } diff --git a/tools/sandbox/config.php b/tools/sandbox/config.php index a206a98d27..59eaa2db2f 100644 --- a/tools/sandbox/config.php +++ b/tools/sandbox/config.php @@ -8,7 +8,9 @@ use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; -if (! file_exists($file = __DIR__ . '/../../vendor/autoload.php')) { +$file = __DIR__ . '/../../vendor/autoload.php'; + +if (! file_exists($file)) { throw new RuntimeException('Install dependencies to run this script.'); }