From 723a7db074d2bfffad79e62c26b16fedc9ff6dcc Mon Sep 17 00:00:00 2001 From: Mohamed Kamel Date: Sat, 29 Sep 2018 21:14:13 +0200 Subject: [PATCH 1/3] - Fixing Config/Config and DoctrineServiceProvider to authenticate with "doctrine/mongodb-odm": "^1.2" using "laravel/lumen-framework": "5.6.*" and PHP 7.2.5 - Applying PSR-2 using "squizlabs/php_codesniffer": "3.*" without including the soft limit of the line length --- src/Config/Config.php | 20 +- .../Command/ClearCache/MetadataCommand.php | 2 +- src/Console/Command/DoctrineCommand.php | 1 - .../Command/GenerateDocumentsCommand.php | 51 +++-- .../Command/GenerateHydratorsCommand.php | 14 +- .../Command/GenerateProxiesCommand.php | 13 +- .../Command/GenerateRepositoriesCommand.php | 12 +- src/Console/Command/QueryCommand.php | 31 ++- src/Console/MetadataFilter.php | 8 +- src/DoctrineServiceProvider.php | 30 ++- src/Filters/TrashedFilter.php | 2 +- src/Infrastructure/DocumentRepository.php | 77 ++++--- src/Infrastructure/Types/DomainIdType.php | 95 ++++----- src/Infrastructure/Types/ShortIdType.php | 95 ++++----- src/Traits/CreatesIdentities.php | 72 +++---- src/Traits/HasIdentity.php | 136 ++++++------ src/Traits/ManagesDocuments.php | 200 +++++++++--------- 17 files changed, 456 insertions(+), 403 deletions(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 29bc0e2..4cc8a62 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -176,11 +176,11 @@ public static function getDB(ConfigRepository $config) */ public static function check(ConfigRepository $config) { - if ( ! isset($config[self::ODM_CONFIG_NAME])) { + if (! isset($config[self::ODM_CONFIG_NAME])) { throw new Exception('Doctrine ODM configuration not registered.'); } - if ( ! isset($config[self::ODM_DB_CONFIG_NAME])) { + if (! isset($config[self::ODM_DB_CONFIG_NAME])) { throw new Exception('Database configuration not registered.'); } } @@ -238,12 +238,18 @@ public static function normalizeConnectionConfig() $config = self::$liveConfig->get(self::ODM_DB_CONFIG_NAME); $dbConfig = $config['connections'][$config['default']]; + $server = $dbConfig['host'] . ':' . $dbConfig['port'] ?? self::DEFAULT_MONGODB_PORT; + $options = array_merge( + [ + 'username' => $dbConfig['username'], + 'password' => $dbConfig['password'] + ], + $dbConfig['options'] ?? [] + ); + return [ - 'host' => $dbConfig['host'], - 'port' => ! empty($dbConfig['port']) ? $dbConfig['port'] : self::DEFAULT_MONGODB_PORT, - 'user' => $dbConfig['username'], - 'password' => $dbConfig['password'], + 'server' => $server, + 'options' => $options ]; } } - diff --git a/src/Console/Command/ClearCache/MetadataCommand.php b/src/Console/Command/ClearCache/MetadataCommand.php index 2c3b323..8bd914b 100644 --- a/src/Console/Command/ClearCache/MetadataCommand.php +++ b/src/Console/Command/ClearCache/MetadataCommand.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $dm = $this->getDocumentManager(); $cacheDriver = $dm->getConfiguration()->getMetadataCacheImpl(); - if ( ! $cacheDriver) { + if (! $cacheDriver) { throw new \InvalidArgumentException('No Metadata cache driver is configured on given DocumentManager.'); } diff --git a/src/Console/Command/DoctrineCommand.php b/src/Console/Command/DoctrineCommand.php index 061c46a..678d33f 100644 --- a/src/Console/Command/DoctrineCommand.php +++ b/src/Console/Command/DoctrineCommand.php @@ -1,7 +1,6 @@ setDescription('Generate document classes and method stubs from your mapping information.') ->setDefinition(array( new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', + null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', InputArgument::REQUIRED, 'The path to generate your document classes.' + 'dest-path', + InputArgument::REQUIRED, + 'The path to generate your document classes.' ), new InputOption( - 'generate-annotations', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should generate annotation metadata on documents.', false + 'generate-annotations', + null, + InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should generate annotation metadata on documents.', + false ), new InputOption( - 'generate-methods', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should generate stub methods on documents.', true + 'generate-methods', + null, + InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should generate stub methods on documents.', + true ), new InputOption( - 'regenerate-documents', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should regenerate a document if it exists.', false + 'regenerate-documents', + null, + InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should regenerate a document if it exists.', + false ), new InputOption( - 'update-documents', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should only update a document if it exists.', true + 'update-documents', + null, + InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should only update a document if it exists.', + true ), new InputOption( - 'extend', null, InputOption::VALUE_OPTIONAL, + 'extend', + null, + InputOption::VALUE_OPTIONAL, 'Defines a base class to be extended by generated document classes.' ), new InputOption( - 'num-spaces', null, InputOption::VALUE_OPTIONAL, - 'Defines the number of indentation spaces.', 4 + 'num-spaces', + null, + InputOption::VALUE_OPTIONAL, + 'Defines the number of indentation spaces.', + 4 ) )) ->setHelp(<<getArgument('dest-path')); - if ( ! file_exists($destPath)) { + if (! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not exist.", $destPath) ); - } elseif ( ! is_writable($destPath)) { + } elseif (! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/GenerateHydratorsCommand.php b/src/Console/Command/GenerateHydratorsCommand.php index 1ed184c..b2cdc52 100644 --- a/src/Console/Command/GenerateHydratorsCommand.php +++ b/src/Console/Command/GenerateHydratorsCommand.php @@ -19,7 +19,6 @@ namespace Nord\Lumen\Doctrine\ODM\MongoDB\Console\Command; - use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console; @@ -46,11 +45,14 @@ protected function configure() ->setDescription('Generates hydrator classes for document classes.') ->setDefinition(array( new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', + null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', InputArgument::OPTIONAL, + 'dest-path', + InputArgument::OPTIONAL, 'The path to generate your hydrator classes. If none is provided, it will attempt to grab from configuration.' ), )) @@ -75,17 +77,17 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $destPath = $dm->getConfiguration()->getHydratorDir(); } - if ( ! is_dir($destPath)) { + if (! is_dir($destPath)) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); - if ( ! file_exists($destPath)) { + if (! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Hydrators destination directory '%s' does not exist.", $destPath) ); - } elseif ( ! is_writable($destPath)) { + } elseif (! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Hydrators destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/GenerateProxiesCommand.php b/src/Console/Command/GenerateProxiesCommand.php index 50c9545..94ad941 100644 --- a/src/Console/Command/GenerateProxiesCommand.php +++ b/src/Console/Command/GenerateProxiesCommand.php @@ -45,11 +45,14 @@ protected function configure() ->setDescription('Generates proxy classes for document classes.') ->setDefinition(array( new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', + null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', InputArgument::OPTIONAL, + 'dest-path', + InputArgument::OPTIONAL, 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' ), )) @@ -74,17 +77,17 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $destPath = $dm->getConfiguration()->getProxyDir(); } - if ( ! is_dir($destPath)) { + if (! is_dir($destPath)) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); - if ( ! file_exists($destPath)) { + if (! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Proxies destination directory '%s' does not exist.", $destPath) ); - } elseif ( ! is_writable($destPath)) { + } elseif (! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Proxies destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/GenerateRepositoriesCommand.php b/src/Console/Command/GenerateRepositoriesCommand.php index b07b198..50ca443 100644 --- a/src/Console/Command/GenerateRepositoriesCommand.php +++ b/src/Console/Command/GenerateRepositoriesCommand.php @@ -46,11 +46,15 @@ protected function configure() ->setDescription('Generate repository classes from your mapping information.') ->setDefinition(array( new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', + null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.' + 'dest-path', + InputArgument::REQUIRED, + 'The path to generate your repository classes.' ) )) ->setHelp(<<getArgument('dest-path')); - if ( ! file_exists($destPath)) { + if (! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not exist.", $destPath) ); - } elseif ( ! is_writable($destPath)) { + } elseif (! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/QueryCommand.php b/src/Console/Command/QueryCommand.php index 52945ee..9d26979 100644 --- a/src/Console/Command/QueryCommand.php +++ b/src/Console/Command/QueryCommand.php @@ -41,28 +41,39 @@ protected function configure() ->setDescription('Query mongodb and inspect the outputted results from your document classes.') ->setDefinition(array( new InputArgument( - 'class', InputArgument::REQUIRED, + 'class', + InputArgument::REQUIRED, 'The class to query.' ), new InputArgument( - 'query', InputArgument::REQUIRED, + 'query', + InputArgument::REQUIRED, 'The query to execute and output the results for.' ), new InputOption( - 'hydrate', null, InputOption::VALUE_NONE, + 'hydrate', + null, + InputOption::VALUE_NONE, 'Whether or not to hydrate the results in to document objects.' ), new InputOption( - 'skip', null, InputOption::VALUE_REQUIRED, + 'skip', + null, + InputOption::VALUE_REQUIRED, 'The number of documents to skip in the cursor.' ), new InputOption( - 'limit', null, InputOption::VALUE_REQUIRED, + 'limit', + null, + InputOption::VALUE_REQUIRED, 'The number of documents to return.' ), new InputOption( - 'depth', null, InputOption::VALUE_REQUIRED, - 'Dumping depth of Document graph.', 7 + 'depth', + null, + InputOption::VALUE_REQUIRED, + 'Dumping depth of Document graph.', + 7 ) )) ->setHelp(<<getOption('depth'); - if ( ! is_numeric($depth)) { + if (! is_numeric($depth)) { throw new \LogicException("Option 'depth' must contain an integer value"); } if (($skip = $input->getOption('skip')) !== null) { - if ( ! is_numeric($skip)) { + if (! is_numeric($skip)) { throw new \LogicException("Option 'skip' must contain an integer value"); } @@ -96,7 +107,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } if (($limit = $input->getOption('limit')) !== null) { - if ( ! is_numeric($limit)) { + if (! is_numeric($limit)) { throw new \LogicException("Option 'limit' must contain an integer value"); } diff --git a/src/Console/MetadataFilter.php b/src/Console/MetadataFilter.php index d16b672..e59d09c 100644 --- a/src/Console/MetadataFilter.php +++ b/src/Console/MetadataFilter.php @@ -46,7 +46,7 @@ public static function filter(array $metadatas, $filter) /** * @var array */ - private $_filter = array(); + private $filter = array(); /** * @param \ArrayIterator $metadata @@ -54,7 +54,7 @@ public static function filter(array $metadatas, $filter) */ public function __construct(\ArrayIterator $metadata, $filter) { - $this->_filter = (array) $filter; + $this->filter = (array) $filter; parent::__construct($metadata); } @@ -63,14 +63,14 @@ public function __construct(\ArrayIterator $metadata, $filter) */ public function accept() { - if (count($this->_filter) == 0) { + if (count($this->filter) == 0) { return true; } $it = $this->getInnerIterator(); $metadata = $it->current(); - foreach ($this->_filter AS $filter) { + foreach ($this->filter as $filter) { if (strpos($metadata->name, $filter) !== false) { return true; } diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index cb71b04..d04c6c8 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -106,15 +106,21 @@ protected function createDocumentManager(ConfigRepository $config) $simpleAnnotations = array_get($doctrineConfig, 'simple_annotations', false); $cache = $this->configureCache($doctrineConfig); - $metadataConfiguration = $this->createMetadataConfiguration($type, $paths, $debug, $proxyDir, $cache, - $simpleAnnotations); + $metadataConfiguration = $this->createMetadataConfiguration( + $type, + $paths, + $debug, + $proxyDir, + $cache, + $simpleAnnotations + ); $this->configureMetadataConfiguration($metadataConfiguration, $doctrineConfig, $databaseConfig); $eventManager = new EventManager; $this->configureEventManager($doctrineConfig, $eventManager); - $connection = new Connection($connectionConfig['host'], [], $metadataConfiguration); + $connection = new Connection($connectionConfig['server'], $connectionConfig['options'], $metadataConfiguration); $documentManager = DocumentManager::create($connection, $metadataConfiguration, $eventManager); @@ -147,8 +153,13 @@ protected function createMetadataConfiguration( ) { switch ($type) { case self::METADATA_ANNOTATIONS: - return Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache, - $useSimpleAnnotationReader); + return Setup::createAnnotationMetadataConfiguration( + $paths, + $isDevMode, + $proxyDir, + $cache, + $useSimpleAnnotationReader + ); case self::METADATA_XML: return Setup::createXMLMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache); case self::METADATA_YAML: @@ -189,7 +200,7 @@ protected function configureMetadataConfiguration( } } - if ( ! empty($doctrineConfig['repository'])) { + if (! empty($doctrineConfig['repository'])) { $configuration->setDefaultRepositoryClassName($doctrineConfig['repository']); } @@ -205,10 +216,9 @@ protected function configureMetadataConfiguration( $configuration->setAutoGenerateHydratorClasses($doctrineConfig['hydrator']['auto_generate']); } } - if ( ! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) { + if (! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) { $configuration->setDefaultDB($databaseConfig['connections'][$databaseConfig['default']]['database']); } - } /** @@ -236,7 +246,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag { if (isset($doctrineConfig['filters'])) { foreach ($doctrineConfig['filters'] as $name => $filter) { - if ( ! array_get($filter, 'enabled', false)) { + if (! array_get($filter, 'enabled', false)) { continue; } $documentManager->getFilterCollection()->enable($name); @@ -246,7 +256,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag // @see http://doctrine-mongodb-odm.readthedocs.org/en/latest/reference/basic-mapping.html#custom-mapping-types if (isset($doctrineConfig['types'])) { foreach ($doctrineConfig['types'] as $name => $className) { - if ( ! Type::hasType($name)) { + if (! Type::hasType($name)) { Type::addType($name, $className); } else { Type::overrideType($name, $className); diff --git a/src/Filters/TrashedFilter.php b/src/Filters/TrashedFilter.php index 020bf11..2214c27 100644 --- a/src/Filters/TrashedFilter.php +++ b/src/Filters/TrashedFilter.php @@ -12,7 +12,7 @@ class TrashedFilter extends SQLFilter */ public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { - if ( ! $this->isSoftDeletable($targetEntity->rootEntityName)) { + if (! $this->isSoftDeletable($targetEntity->rootEntityName)) { return ''; } diff --git a/src/Infrastructure/DocumentRepository.php b/src/Infrastructure/DocumentRepository.php index 501b2a0..b6b6a40 100644 --- a/src/Infrastructure/DocumentRepository.php +++ b/src/Infrastructure/DocumentRepository.php @@ -1,39 +1,38 @@ -findOneBy(['domain_id' => $domainId]); - } - - /** - * @param string $domainId - * - * @return int - */ - public function domainIdExists($domainId) - { - return (int)$this->createQueryBuilder() - ->field('domain_id') - ->equals($domainId) - ->getQuery() - ->count(); - } - -} \ No newline at end of file +findOneBy(['domain_id' => $domainId]); + } + + /** + * @param string $domainId + * + * @return int + */ + public function domainIdExists($domainId) + { + return (int)$this->createQueryBuilder() + ->field('domain_id') + ->equals($domainId) + ->getQuery() + ->count(); + } +} diff --git a/src/Infrastructure/Types/DomainIdType.php b/src/Infrastructure/Types/DomainIdType.php index 443b675..5868cd7 100644 --- a/src/Infrastructure/Types/DomainIdType.php +++ b/src/Infrastructure/Types/DomainIdType.php @@ -1,48 +1,47 @@ -getValue() : $value; - } - - /** - * @inheritdoc - */ - public function convertToPHPValue($value) - { - return new DomainId($value); - } - - /** - * @inheritdoc - */ - public function closureToMongo() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; - } - - /** - * @inheritdoc - */ - public function closureToPHP() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; - } - -} \ No newline at end of file +getValue() : $value; + } + + /** + * @inheritdoc + */ + public function convertToPHPValue($value) + { + return new DomainId($value); + } + + /** + * @inheritdoc + */ + public function closureToMongo() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; + } + + /** + * @inheritdoc + */ + public function closureToPHP() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; + } +} diff --git a/src/Infrastructure/Types/ShortIdType.php b/src/Infrastructure/Types/ShortIdType.php index e8a8a21..1e138d2 100644 --- a/src/Infrastructure/Types/ShortIdType.php +++ b/src/Infrastructure/Types/ShortIdType.php @@ -1,48 +1,47 @@ -getValue() : $value; - } - - /** - * @inheritdoc - */ - public function convertToPHPValue($value) - { - return new ShortId($value); - } - - /** - * @inheritdoc - */ - public function closureToMongo() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; - } - - /** - * @inheritdoc - */ - public function closureToPHP() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; - } - -} \ No newline at end of file +getValue() : $value; + } + + /** + * @inheritdoc + */ + public function convertToPHPValue($value) + { + return new ShortId($value); + } + + /** + * @inheritdoc + */ + public function closureToMongo() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; + } + + /** + * @inheritdoc + */ + public function closureToPHP() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; + } +} diff --git a/src/Traits/CreatesIdentities.php b/src/Traits/CreatesIdentities.php index c5c6595..4fa8050 100644 --- a/src/Traits/CreatesIdentities.php +++ b/src/Traits/CreatesIdentities.php @@ -1,36 +1,36 @@ -= 10) { - throw new \Exception('Failed to generate a unique identifier.'); - } - } while (call_user_func($objectIdExists, $domainId->getValue())); - - return $domainId; - } -} \ No newline at end of file += 10) { + throw new \Exception('Failed to generate a unique identifier.'); + } + } while (call_user_func($objectIdExists, $domainId->getValue())); + + return $domainId; + } +} diff --git a/src/Traits/HasIdentity.php b/src/Traits/HasIdentity.php index f46b35c..7148170 100644 --- a/src/Traits/HasIdentity.php +++ b/src/Traits/HasIdentity.php @@ -1,68 +1,68 @@ -domainId->getValue() === $domainId->getValue(); - } - - /** - * @return DomainId - */ - public function getDomainId() - { - return $this->domainId; - } - - /** - * @return string - */ - public function getDomainIdValue() - { - return $this->getDomainId()->getValue(); - } - - /** - * @param null|string $value - * - * @throws \Exception - */ - private function createDomainId($value = null) - { - $this->setDomainId(new DomainId($value)); - } - - /** - * @param DomainId $domainId - * - * @throws \Exception - */ - private function setDomainId(DomainId $domainId) - { - if ($this->domainId !== null) { - throw new \Exception('Domain ID cannot be changed.'); - } - - $this->domainId = $domainId; - } -} +domainId->getValue() === $domainId->getValue(); + } + + /** + * @return DomainId + */ + public function getDomainId() + { + return $this->domainId; + } + + /** + * @return string + */ + public function getDomainIdValue() + { + return $this->getDomainId()->getValue(); + } + + /** + * @param null|string $value + * + * @throws \Exception + */ + private function createDomainId($value = null) + { + $this->setDomainId(new DomainId($value)); + } + + /** + * @param DomainId $domainId + * + * @throws \Exception + */ + private function setDomainId(DomainId $domainId) + { + if ($this->domainId !== null) { + throw new \Exception('Domain ID cannot be changed.'); + } + + $this->domainId = $domainId; + } +} diff --git a/src/Traits/ManagesDocuments.php b/src/Traits/ManagesDocuments.php index de95819..64c6ecd 100644 --- a/src/Traits/ManagesDocuments.php +++ b/src/Traits/ManagesDocuments.php @@ -1,100 +1,100 @@ -getDocumentManager()->persist($document); - } - - /** - * @param mixed $document - */ - private function saveDocumentAndCommit($document) - { - $this->saveDocument($document); - $this->commitDocuments(); - } - - /** - * @param mixed $document - */ - private function updateDocument($document) - { - $this->getDocumentManager()->merge($document); - } - - /** - * @param mixed $document - */ - private function updateDocumentAndCommit($document) - { - $this->updateDocument($document); - $this->commitDocuments(); - } - - /** - * @param mixed $document - */ - private function deleteDocument($document) - { - $this->getDocumentManager()->remove($document); - } - - /** - * @param mixed $document - */ - private function deleteDocumentAndCommit($document) - { - $this->deleteDocument($document); - $this->commitDocuments(); - } - - /** - * - */ - private function commitDocuments() - { - $this->getDocumentManager()->flush(); - } - - /** - * @param mixed $document - */ - private function refreshDocument($document) - { - $this->getDocumentManager()->refresh($document); - } - - /** - * @param string $documentClassName - * - * @return DocumentRepository - */ - private function getDocumentRepository($documentClassName) - { - return $this->getDocumentManager()->getRepository($documentClassName); - } - - /** - * @return DocumentManager - */ - private function getDocumentManager() - { - return app(DocumentManager::class); - } -} \ No newline at end of file +getDocumentManager()->persist($document); + } + + /** + * @param mixed $document + */ + private function saveDocumentAndCommit($document) + { + $this->saveDocument($document); + $this->commitDocuments(); + } + + /** + * @param mixed $document + */ + private function updateDocument($document) + { + $this->getDocumentManager()->merge($document); + } + + /** + * @param mixed $document + */ + private function updateDocumentAndCommit($document) + { + $this->updateDocument($document); + $this->commitDocuments(); + } + + /** + * @param mixed $document + */ + private function deleteDocument($document) + { + $this->getDocumentManager()->remove($document); + } + + /** + * @param mixed $document + */ + private function deleteDocumentAndCommit($document) + { + $this->deleteDocument($document); + $this->commitDocuments(); + } + + /** + * + */ + private function commitDocuments() + { + $this->getDocumentManager()->flush(); + } + + /** + * @param mixed $document + */ + private function refreshDocument($document) + { + $this->getDocumentManager()->refresh($document); + } + + /** + * @param string $documentClassName + * + * @return DocumentRepository + */ + private function getDocumentRepository($documentClassName) + { + return $this->getDocumentManager()->getRepository($documentClassName); + } + + /** + * @return DocumentManager + */ + private function getDocumentManager() + { + return app(DocumentManager::class); + } +} From cffd752906ffb2d6360d33c802ff18db85752f20 Mon Sep 17 00:00:00 2001 From: Mohamed Kamel Date: Sat, 29 Sep 2018 23:11:51 +0200 Subject: [PATCH 2/3] - applying styleci instead of php code sniffer --- src/Config/Config.php | 5 +- .../Command/ClearCache/MetadataCommand.php | 2 +- src/Console/Command/DoctrineCommand.php | 1 + .../Command/GenerateDocumentsCommand.php | 51 ++--- .../Command/GenerateHydratorsCommand.php | 14 +- .../Command/GenerateProxiesCommand.php | 13 +- .../Command/GenerateRepositoriesCommand.php | 12 +- src/Console/Command/QueryCommand.php | 31 +-- src/Console/MetadataFilter.php | 8 +- src/DoctrineServiceProvider.php | 28 +-- src/Filters/TrashedFilter.php | 2 +- src/Infrastructure/DocumentRepository.php | 77 +++---- src/Infrastructure/Types/DomainIdType.php | 95 +++++---- src/Infrastructure/Types/ShortIdType.php | 95 +++++---- src/Traits/CreatesIdentities.php | 72 +++---- src/Traits/HasIdentity.php | 136 ++++++------ src/Traits/ManagesDocuments.php | 200 +++++++++--------- 17 files changed, 398 insertions(+), 444 deletions(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 4cc8a62..5a32308 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -176,11 +176,11 @@ public static function getDB(ConfigRepository $config) */ public static function check(ConfigRepository $config) { - if (! isset($config[self::ODM_CONFIG_NAME])) { + if ( ! isset($config[self::ODM_CONFIG_NAME])) { throw new Exception('Doctrine ODM configuration not registered.'); } - if (! isset($config[self::ODM_DB_CONFIG_NAME])) { + if ( ! isset($config[self::ODM_DB_CONFIG_NAME])) { throw new Exception('Database configuration not registered.'); } } @@ -253,3 +253,4 @@ public static function normalizeConnectionConfig() ]; } } + diff --git a/src/Console/Command/ClearCache/MetadataCommand.php b/src/Console/Command/ClearCache/MetadataCommand.php index 8bd914b..2c3b323 100644 --- a/src/Console/Command/ClearCache/MetadataCommand.php +++ b/src/Console/Command/ClearCache/MetadataCommand.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $dm = $this->getDocumentManager(); $cacheDriver = $dm->getConfiguration()->getMetadataCacheImpl(); - if (! $cacheDriver) { + if ( ! $cacheDriver) { throw new \InvalidArgumentException('No Metadata cache driver is configured on given DocumentManager.'); } diff --git a/src/Console/Command/DoctrineCommand.php b/src/Console/Command/DoctrineCommand.php index 678d33f..061c46a 100644 --- a/src/Console/Command/DoctrineCommand.php +++ b/src/Console/Command/DoctrineCommand.php @@ -1,6 +1,7 @@ setDescription('Generate document classes and method stubs from your mapping information.') ->setDefinition(array( new InputOption( - 'filter', - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', - InputArgument::REQUIRED, - 'The path to generate your document classes.' + 'dest-path', InputArgument::REQUIRED, 'The path to generate your document classes.' ), new InputOption( - 'generate-annotations', - null, - InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should generate annotation metadata on documents.', - false + 'generate-annotations', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should generate annotation metadata on documents.', false ), new InputOption( - 'generate-methods', - null, - InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should generate stub methods on documents.', - true + 'generate-methods', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should generate stub methods on documents.', true ), new InputOption( - 'regenerate-documents', - null, - InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should regenerate a document if it exists.', - false + 'regenerate-documents', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should regenerate a document if it exists.', false ), new InputOption( - 'update-documents', - null, - InputOption::VALUE_OPTIONAL, - 'Flag to define if the generator should only update a document if it exists.', - true + 'update-documents', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if the generator should only update a document if it exists.', true ), new InputOption( - 'extend', - null, - InputOption::VALUE_OPTIONAL, + 'extend', null, InputOption::VALUE_OPTIONAL, 'Defines a base class to be extended by generated document classes.' ), new InputOption( - 'num-spaces', - null, - InputOption::VALUE_OPTIONAL, - 'Defines the number of indentation spaces.', - 4 + 'num-spaces', null, InputOption::VALUE_OPTIONAL, + 'Defines the number of indentation spaces.', 4 ) )) ->setHelp(<<getArgument('dest-path')); - if (! file_exists($destPath)) { + if ( ! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not exist.", $destPath) ); - } elseif (! is_writable($destPath)) { + } elseif ( ! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/GenerateHydratorsCommand.php b/src/Console/Command/GenerateHydratorsCommand.php index b2cdc52..1ed184c 100644 --- a/src/Console/Command/GenerateHydratorsCommand.php +++ b/src/Console/Command/GenerateHydratorsCommand.php @@ -19,6 +19,7 @@ namespace Nord\Lumen\Doctrine\ODM\MongoDB\Console\Command; + use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console; @@ -45,14 +46,11 @@ protected function configure() ->setDescription('Generates hydrator classes for document classes.') ->setDefinition(array( new InputOption( - 'filter', - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', - InputArgument::OPTIONAL, + 'dest-path', InputArgument::OPTIONAL, 'The path to generate your hydrator classes. If none is provided, it will attempt to grab from configuration.' ), )) @@ -77,17 +75,17 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $destPath = $dm->getConfiguration()->getHydratorDir(); } - if (! is_dir($destPath)) { + if ( ! is_dir($destPath)) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); - if (! file_exists($destPath)) { + if ( ! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Hydrators destination directory '%s' does not exist.", $destPath) ); - } elseif (! is_writable($destPath)) { + } elseif ( ! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Hydrators destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/GenerateProxiesCommand.php b/src/Console/Command/GenerateProxiesCommand.php index 94ad941..50c9545 100644 --- a/src/Console/Command/GenerateProxiesCommand.php +++ b/src/Console/Command/GenerateProxiesCommand.php @@ -45,14 +45,11 @@ protected function configure() ->setDescription('Generates proxy classes for document classes.') ->setDefinition(array( new InputOption( - 'filter', - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', - InputArgument::OPTIONAL, + 'dest-path', InputArgument::OPTIONAL, 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' ), )) @@ -77,17 +74,17 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $destPath = $dm->getConfiguration()->getProxyDir(); } - if (! is_dir($destPath)) { + if ( ! is_dir($destPath)) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); - if (! file_exists($destPath)) { + if ( ! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Proxies destination directory '%s' does not exist.", $destPath) ); - } elseif (! is_writable($destPath)) { + } elseif ( ! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Proxies destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/GenerateRepositoriesCommand.php b/src/Console/Command/GenerateRepositoriesCommand.php index 50ca443..b07b198 100644 --- a/src/Console/Command/GenerateRepositoriesCommand.php +++ b/src/Console/Command/GenerateRepositoriesCommand.php @@ -46,15 +46,11 @@ protected function configure() ->setDescription('Generate repository classes from your mapping information.') ->setDefinition(array( new InputOption( - 'filter', - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match documents that should be processed.' ), new InputArgument( - 'dest-path', - InputArgument::REQUIRED, - 'The path to generate your repository classes.' + 'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.' ) )) ->setHelp(<<getArgument('dest-path')); - if (! file_exists($destPath)) { + if ( ! file_exists($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not exist.", $destPath) ); - } elseif (! is_writable($destPath)) { + } elseif ( ! is_writable($destPath)) { throw new \InvalidArgumentException( sprintf("Documents destination directory '%s' does not have write permissions.", $destPath) ); diff --git a/src/Console/Command/QueryCommand.php b/src/Console/Command/QueryCommand.php index 9d26979..52945ee 100644 --- a/src/Console/Command/QueryCommand.php +++ b/src/Console/Command/QueryCommand.php @@ -41,39 +41,28 @@ protected function configure() ->setDescription('Query mongodb and inspect the outputted results from your document classes.') ->setDefinition(array( new InputArgument( - 'class', - InputArgument::REQUIRED, + 'class', InputArgument::REQUIRED, 'The class to query.' ), new InputArgument( - 'query', - InputArgument::REQUIRED, + 'query', InputArgument::REQUIRED, 'The query to execute and output the results for.' ), new InputOption( - 'hydrate', - null, - InputOption::VALUE_NONE, + 'hydrate', null, InputOption::VALUE_NONE, 'Whether or not to hydrate the results in to document objects.' ), new InputOption( - 'skip', - null, - InputOption::VALUE_REQUIRED, + 'skip', null, InputOption::VALUE_REQUIRED, 'The number of documents to skip in the cursor.' ), new InputOption( - 'limit', - null, - InputOption::VALUE_REQUIRED, + 'limit', null, InputOption::VALUE_REQUIRED, 'The number of documents to return.' ), new InputOption( - 'depth', - null, - InputOption::VALUE_REQUIRED, - 'Dumping depth of Document graph.', - 7 + 'depth', null, InputOption::VALUE_REQUIRED, + 'Dumping depth of Document graph.', 7 ) )) ->setHelp(<<getOption('depth'); - if (! is_numeric($depth)) { + if ( ! is_numeric($depth)) { throw new \LogicException("Option 'depth' must contain an integer value"); } if (($skip = $input->getOption('skip')) !== null) { - if (! is_numeric($skip)) { + if ( ! is_numeric($skip)) { throw new \LogicException("Option 'skip' must contain an integer value"); } @@ -107,7 +96,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } if (($limit = $input->getOption('limit')) !== null) { - if (! is_numeric($limit)) { + if ( ! is_numeric($limit)) { throw new \LogicException("Option 'limit' must contain an integer value"); } diff --git a/src/Console/MetadataFilter.php b/src/Console/MetadataFilter.php index e59d09c..d16b672 100644 --- a/src/Console/MetadataFilter.php +++ b/src/Console/MetadataFilter.php @@ -46,7 +46,7 @@ public static function filter(array $metadatas, $filter) /** * @var array */ - private $filter = array(); + private $_filter = array(); /** * @param \ArrayIterator $metadata @@ -54,7 +54,7 @@ public static function filter(array $metadatas, $filter) */ public function __construct(\ArrayIterator $metadata, $filter) { - $this->filter = (array) $filter; + $this->_filter = (array) $filter; parent::__construct($metadata); } @@ -63,14 +63,14 @@ public function __construct(\ArrayIterator $metadata, $filter) */ public function accept() { - if (count($this->filter) == 0) { + if (count($this->_filter) == 0) { return true; } $it = $this->getInnerIterator(); $metadata = $it->current(); - foreach ($this->filter as $filter) { + foreach ($this->_filter AS $filter) { if (strpos($metadata->name, $filter) !== false) { return true; } diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index d04c6c8..2356d49 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -106,14 +106,8 @@ protected function createDocumentManager(ConfigRepository $config) $simpleAnnotations = array_get($doctrineConfig, 'simple_annotations', false); $cache = $this->configureCache($doctrineConfig); - $metadataConfiguration = $this->createMetadataConfiguration( - $type, - $paths, - $debug, - $proxyDir, - $cache, - $simpleAnnotations - ); + $metadataConfiguration = $this->createMetadataConfiguration($type, $paths, $debug, $proxyDir, $cache, + $simpleAnnotations); $this->configureMetadataConfiguration($metadataConfiguration, $doctrineConfig, $databaseConfig); @@ -153,13 +147,8 @@ protected function createMetadataConfiguration( ) { switch ($type) { case self::METADATA_ANNOTATIONS: - return Setup::createAnnotationMetadataConfiguration( - $paths, - $isDevMode, - $proxyDir, - $cache, - $useSimpleAnnotationReader - ); + return Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache, + $useSimpleAnnotationReader); case self::METADATA_XML: return Setup::createXMLMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache); case self::METADATA_YAML: @@ -200,7 +189,7 @@ protected function configureMetadataConfiguration( } } - if (! empty($doctrineConfig['repository'])) { + if ( ! empty($doctrineConfig['repository'])) { $configuration->setDefaultRepositoryClassName($doctrineConfig['repository']); } @@ -216,9 +205,10 @@ protected function configureMetadataConfiguration( $configuration->setAutoGenerateHydratorClasses($doctrineConfig['hydrator']['auto_generate']); } } - if (! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) { + if ( ! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) { $configuration->setDefaultDB($databaseConfig['connections'][$databaseConfig['default']]['database']); } + } /** @@ -246,7 +236,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag { if (isset($doctrineConfig['filters'])) { foreach ($doctrineConfig['filters'] as $name => $filter) { - if (! array_get($filter, 'enabled', false)) { + if ( ! array_get($filter, 'enabled', false)) { continue; } $documentManager->getFilterCollection()->enable($name); @@ -256,7 +246,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag // @see http://doctrine-mongodb-odm.readthedocs.org/en/latest/reference/basic-mapping.html#custom-mapping-types if (isset($doctrineConfig['types'])) { foreach ($doctrineConfig['types'] as $name => $className) { - if (! Type::hasType($name)) { + if ( ! Type::hasType($name)) { Type::addType($name, $className); } else { Type::overrideType($name, $className); diff --git a/src/Filters/TrashedFilter.php b/src/Filters/TrashedFilter.php index 2214c27..020bf11 100644 --- a/src/Filters/TrashedFilter.php +++ b/src/Filters/TrashedFilter.php @@ -12,7 +12,7 @@ class TrashedFilter extends SQLFilter */ public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { - if (! $this->isSoftDeletable($targetEntity->rootEntityName)) { + if ( ! $this->isSoftDeletable($targetEntity->rootEntityName)) { return ''; } diff --git a/src/Infrastructure/DocumentRepository.php b/src/Infrastructure/DocumentRepository.php index b6b6a40..501b2a0 100644 --- a/src/Infrastructure/DocumentRepository.php +++ b/src/Infrastructure/DocumentRepository.php @@ -1,38 +1,39 @@ -findOneBy(['domain_id' => $domainId]); - } - - /** - * @param string $domainId - * - * @return int - */ - public function domainIdExists($domainId) - { - return (int)$this->createQueryBuilder() - ->field('domain_id') - ->equals($domainId) - ->getQuery() - ->count(); - } -} +findOneBy(['domain_id' => $domainId]); + } + + /** + * @param string $domainId + * + * @return int + */ + public function domainIdExists($domainId) + { + return (int)$this->createQueryBuilder() + ->field('domain_id') + ->equals($domainId) + ->getQuery() + ->count(); + } + +} \ No newline at end of file diff --git a/src/Infrastructure/Types/DomainIdType.php b/src/Infrastructure/Types/DomainIdType.php index 5868cd7..443b675 100644 --- a/src/Infrastructure/Types/DomainIdType.php +++ b/src/Infrastructure/Types/DomainIdType.php @@ -1,47 +1,48 @@ -getValue() : $value; - } - - /** - * @inheritdoc - */ - public function convertToPHPValue($value) - { - return new DomainId($value); - } - - /** - * @inheritdoc - */ - public function closureToMongo() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; - } - - /** - * @inheritdoc - */ - public function closureToPHP() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; - } -} +getValue() : $value; + } + + /** + * @inheritdoc + */ + public function convertToPHPValue($value) + { + return new DomainId($value); + } + + /** + * @inheritdoc + */ + public function closureToMongo() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; + } + + /** + * @inheritdoc + */ + public function closureToPHP() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\DomainId($value);'; + } + +} \ No newline at end of file diff --git a/src/Infrastructure/Types/ShortIdType.php b/src/Infrastructure/Types/ShortIdType.php index 1e138d2..e8a8a21 100644 --- a/src/Infrastructure/Types/ShortIdType.php +++ b/src/Infrastructure/Types/ShortIdType.php @@ -1,47 +1,48 @@ -getValue() : $value; - } - - /** - * @inheritdoc - */ - public function convertToPHPValue($value) - { - return new ShortId($value); - } - - /** - * @inheritdoc - */ - public function closureToMongo() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; - } - - /** - * @inheritdoc - */ - public function closureToPHP() - { - return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; - } -} +getValue() : $value; + } + + /** + * @inheritdoc + */ + public function convertToPHPValue($value) + { + return new ShortId($value); + } + + /** + * @inheritdoc + */ + public function closureToMongo() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; + } + + /** + * @inheritdoc + */ + public function closureToPHP() + { + return '$return = new \Nord\Lumen\Doctrine\ODM\MongoDB\Domain\Model\ShortId($value);'; + } + +} \ No newline at end of file diff --git a/src/Traits/CreatesIdentities.php b/src/Traits/CreatesIdentities.php index 4fa8050..c5c6595 100644 --- a/src/Traits/CreatesIdentities.php +++ b/src/Traits/CreatesIdentities.php @@ -1,36 +1,36 @@ -= 10) { - throw new \Exception('Failed to generate a unique identifier.'); - } - } while (call_user_func($objectIdExists, $domainId->getValue())); - - return $domainId; - } -} += 10) { + throw new \Exception('Failed to generate a unique identifier.'); + } + } while (call_user_func($objectIdExists, $domainId->getValue())); + + return $domainId; + } +} \ No newline at end of file diff --git a/src/Traits/HasIdentity.php b/src/Traits/HasIdentity.php index 7148170..f46b35c 100644 --- a/src/Traits/HasIdentity.php +++ b/src/Traits/HasIdentity.php @@ -1,68 +1,68 @@ -domainId->getValue() === $domainId->getValue(); - } - - /** - * @return DomainId - */ - public function getDomainId() - { - return $this->domainId; - } - - /** - * @return string - */ - public function getDomainIdValue() - { - return $this->getDomainId()->getValue(); - } - - /** - * @param null|string $value - * - * @throws \Exception - */ - private function createDomainId($value = null) - { - $this->setDomainId(new DomainId($value)); - } - - /** - * @param DomainId $domainId - * - * @throws \Exception - */ - private function setDomainId(DomainId $domainId) - { - if ($this->domainId !== null) { - throw new \Exception('Domain ID cannot be changed.'); - } - - $this->domainId = $domainId; - } -} +domainId->getValue() === $domainId->getValue(); + } + + /** + * @return DomainId + */ + public function getDomainId() + { + return $this->domainId; + } + + /** + * @return string + */ + public function getDomainIdValue() + { + return $this->getDomainId()->getValue(); + } + + /** + * @param null|string $value + * + * @throws \Exception + */ + private function createDomainId($value = null) + { + $this->setDomainId(new DomainId($value)); + } + + /** + * @param DomainId $domainId + * + * @throws \Exception + */ + private function setDomainId(DomainId $domainId) + { + if ($this->domainId !== null) { + throw new \Exception('Domain ID cannot be changed.'); + } + + $this->domainId = $domainId; + } +} diff --git a/src/Traits/ManagesDocuments.php b/src/Traits/ManagesDocuments.php index 64c6ecd..de95819 100644 --- a/src/Traits/ManagesDocuments.php +++ b/src/Traits/ManagesDocuments.php @@ -1,100 +1,100 @@ -getDocumentManager()->persist($document); - } - - /** - * @param mixed $document - */ - private function saveDocumentAndCommit($document) - { - $this->saveDocument($document); - $this->commitDocuments(); - } - - /** - * @param mixed $document - */ - private function updateDocument($document) - { - $this->getDocumentManager()->merge($document); - } - - /** - * @param mixed $document - */ - private function updateDocumentAndCommit($document) - { - $this->updateDocument($document); - $this->commitDocuments(); - } - - /** - * @param mixed $document - */ - private function deleteDocument($document) - { - $this->getDocumentManager()->remove($document); - } - - /** - * @param mixed $document - */ - private function deleteDocumentAndCommit($document) - { - $this->deleteDocument($document); - $this->commitDocuments(); - } - - /** - * - */ - private function commitDocuments() - { - $this->getDocumentManager()->flush(); - } - - /** - * @param mixed $document - */ - private function refreshDocument($document) - { - $this->getDocumentManager()->refresh($document); - } - - /** - * @param string $documentClassName - * - * @return DocumentRepository - */ - private function getDocumentRepository($documentClassName) - { - return $this->getDocumentManager()->getRepository($documentClassName); - } - - /** - * @return DocumentManager - */ - private function getDocumentManager() - { - return app(DocumentManager::class); - } -} +getDocumentManager()->persist($document); + } + + /** + * @param mixed $document + */ + private function saveDocumentAndCommit($document) + { + $this->saveDocument($document); + $this->commitDocuments(); + } + + /** + * @param mixed $document + */ + private function updateDocument($document) + { + $this->getDocumentManager()->merge($document); + } + + /** + * @param mixed $document + */ + private function updateDocumentAndCommit($document) + { + $this->updateDocument($document); + $this->commitDocuments(); + } + + /** + * @param mixed $document + */ + private function deleteDocument($document) + { + $this->getDocumentManager()->remove($document); + } + + /** + * @param mixed $document + */ + private function deleteDocumentAndCommit($document) + { + $this->deleteDocument($document); + $this->commitDocuments(); + } + + /** + * + */ + private function commitDocuments() + { + $this->getDocumentManager()->flush(); + } + + /** + * @param mixed $document + */ + private function refreshDocument($document) + { + $this->getDocumentManager()->refresh($document); + } + + /** + * @param string $documentClassName + * + * @return DocumentRepository + */ + private function getDocumentRepository($documentClassName) + { + return $this->getDocumentManager()->getRepository($documentClassName); + } + + /** + * @return DocumentManager + */ + private function getDocumentManager() + { + return app(DocumentManager::class); + } +} \ No newline at end of file From 19830578a389395ee85b38c7942f5bfd93e469bc Mon Sep 17 00:00:00 2001 From: Mohamed Kamel Date: Sun, 30 Sep 2018 11:51:56 +0200 Subject: [PATCH 3/3] Fix style --- src/Config/Config.php | 5 ++--- src/DoctrineServiceProvider.php | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Config/Config.php b/src/Config/Config.php index 5a32308..4cc8a62 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -176,11 +176,11 @@ public static function getDB(ConfigRepository $config) */ public static function check(ConfigRepository $config) { - if ( ! isset($config[self::ODM_CONFIG_NAME])) { + if (! isset($config[self::ODM_CONFIG_NAME])) { throw new Exception('Doctrine ODM configuration not registered.'); } - if ( ! isset($config[self::ODM_DB_CONFIG_NAME])) { + if (! isset($config[self::ODM_DB_CONFIG_NAME])) { throw new Exception('Database configuration not registered.'); } } @@ -253,4 +253,3 @@ public static function normalizeConnectionConfig() ]; } } - diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index 2356d49..d04c6c8 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -106,8 +106,14 @@ protected function createDocumentManager(ConfigRepository $config) $simpleAnnotations = array_get($doctrineConfig, 'simple_annotations', false); $cache = $this->configureCache($doctrineConfig); - $metadataConfiguration = $this->createMetadataConfiguration($type, $paths, $debug, $proxyDir, $cache, - $simpleAnnotations); + $metadataConfiguration = $this->createMetadataConfiguration( + $type, + $paths, + $debug, + $proxyDir, + $cache, + $simpleAnnotations + ); $this->configureMetadataConfiguration($metadataConfiguration, $doctrineConfig, $databaseConfig); @@ -147,8 +153,13 @@ protected function createMetadataConfiguration( ) { switch ($type) { case self::METADATA_ANNOTATIONS: - return Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache, - $useSimpleAnnotationReader); + return Setup::createAnnotationMetadataConfiguration( + $paths, + $isDevMode, + $proxyDir, + $cache, + $useSimpleAnnotationReader + ); case self::METADATA_XML: return Setup::createXMLMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache); case self::METADATA_YAML: @@ -189,7 +200,7 @@ protected function configureMetadataConfiguration( } } - if ( ! empty($doctrineConfig['repository'])) { + if (! empty($doctrineConfig['repository'])) { $configuration->setDefaultRepositoryClassName($doctrineConfig['repository']); } @@ -205,10 +216,9 @@ protected function configureMetadataConfiguration( $configuration->setAutoGenerateHydratorClasses($doctrineConfig['hydrator']['auto_generate']); } } - if ( ! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) { + if (! empty($databaseConfig['connections'][$databaseConfig['default']]['database'])) { $configuration->setDefaultDB($databaseConfig['connections'][$databaseConfig['default']]['database']); } - } /** @@ -236,7 +246,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag { if (isset($doctrineConfig['filters'])) { foreach ($doctrineConfig['filters'] as $name => $filter) { - if ( ! array_get($filter, 'enabled', false)) { + if (! array_get($filter, 'enabled', false)) { continue; } $documentManager->getFilterCollection()->enable($name); @@ -246,7 +256,7 @@ protected function configureDocumentManager(array $doctrineConfig, DocumentManag // @see http://doctrine-mongodb-odm.readthedocs.org/en/latest/reference/basic-mapping.html#custom-mapping-types if (isset($doctrineConfig['types'])) { foreach ($doctrineConfig['types'] as $name => $className) { - if ( ! Type::hasType($name)) { + if (! Type::hasType($name)) { Type::addType($name, $className); } else { Type::overrideType($name, $className);