Skip to content

Commit

Permalink
Merge pull request #1749 from carusogabriel/cs-fixes-alias-functions
Browse files Browse the repository at this point in the history
[CS] Start to fix excluded ones
  • Loading branch information
alcaeus committed Mar 12, 2018
2 parents 11e3fe0 + 1fb8a32 commit 5e07b23
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 29 deletions.
10 changes: 7 additions & 3 deletions lib/Doctrine/ODM/MongoDB/DocumentManager.php
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions lib/Doctrine/ODM/MongoDB/DocumentRepository.php
Expand Up @@ -108,7 +108,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);
}
Expand All @@ -126,7 +127,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);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Expand Up @@ -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;
Expand Down Expand Up @@ -886,7 +885,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());
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/MongoDBException.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -115,7 +114,7 @@ private function generateCollectionClass($for, $targetFqcn, $fileName)
{
$exploded = explode('\\', $targetFqcn);
$class = array_pop($exploded);
$namespace = join('\\', $exploded);
$namespace = implode('\\', $exploded);
$code = <<<CODE
<?php
Expand Down Expand Up @@ -218,8 +217,9 @@ private function buildParametersString(\ReflectionMethod $method)
/* @var $param \ReflectionParameter */
foreach ($parameters as $param) {
$parameterDefinition = '';
$parameterType = $this->getParameterType($param);

if ($parameterType = $this->getParameterType($param)) {
if ($parameterType) {
$parameterDefinition .= $parameterType . ' ';
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ODM/MongoDB/SchemaManager.php
Expand Up @@ -224,7 +224,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'];
Expand Down
Expand Up @@ -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();
}

Expand Down
Expand Up @@ -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();
}

Expand Down
Expand Up @@ -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();
}

Expand Down
Expand Up @@ -84,15 +84,17 @@ 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");
}

$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");
}
Expand Down
3 changes: 0 additions & 3 deletions phpcs.xml.dist
Expand Up @@ -42,12 +42,9 @@
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedFOREACH" />
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedIF" />
<exclude name="Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase" />
<exclude name="Generic.PHP.ForbiddenFunctions.Found" />
<exclude name="Generic.PHP.ForbiddenFunctions.FoundWithAlternative" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.AssignmentInCondition" />
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit" />
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod" />
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty" />
Expand Down
3 changes: 2 additions & 1 deletion tests/Documents/Ecommerce/ConfigurableProduct.php
Expand Up @@ -85,7 +85,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) {
Expand Down
4 changes: 3 additions & 1 deletion tests/bootstrap.php
Expand Up @@ -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.');
}

Expand Down
4 changes: 3 additions & 1 deletion tools/sandbox/config.php
Expand Up @@ -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.');
}

Expand Down

0 comments on commit 5e07b23

Please sign in to comment.