Skip to content

Commit

Permalink
Style and documentation fixes; removed explicit selectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarcher committed Nov 6, 2015
1 parent 14ab621 commit 0b86153
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
7 changes: 0 additions & 7 deletions lib/Doctrine/ODM/PHPCR/Query/Builder/ConverterPhpcr.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,6 @@ public function getQuery(QueryBuilder $builder)
);
}

// be explicit in what we select
if (empty($this->columns)) {
foreach (array_keys($this->sourceDocumentNodes) as $selectorName) {
$this->columns[] = $this->qomf->column($selectorName);
}
}

// for each document source add phpcr:{class,classparents} restrictions
foreach ($this->sourceDocumentNodes as $sourceNode) {
$documentFqn = $this->aliasMetadata[$sourceNode->getAlias()]->getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Show information about mapped documents
* Verify that any documents which are mapped as having unique
* node types are truly unique.
*/
class VerifyUniqueNodeTypesMappingCommand extends Command
{
Expand All @@ -37,11 +38,11 @@ protected function configure()
parent::configure();

$this
->setName('doctrine:phpcr:mapping:verify_unique_node_types')
->setDescription('Verify that documents with unique node types are correctly mapped')
->setName('doctrine:phpcr:mapping:verify-unique-node-types')
->setDescription('Verify that documents claiming to have unique node types are truly unique')
->setHelp(<<<EOT
The <info>%command.name%</info> command checks all mapped PHPCR-ODM documents
and verifies that any marked as having unique node types are, in fact, unique.
and verifies that any claiming to use unique node types are truly unique.
EOT
);
}
Expand All @@ -52,8 +53,20 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$documentManager = $this->getHelper('phpcr')->getDocumentManager();
$uniqueNodeTypeHelper = new UniqueNodeTypeHelper();

UniqueNodeTypeHelper::checkNodeTypeMappings($documentManager, $output);
$debugInformation = $uniqueNodeTypeHelper->checkNodeTypeMappings($documentManager);

if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
foreach ($debugInformation as $className => $debug) {
$output->writeln(sprintf(
'The document <info>%s</info> uses %snode type <info>%s</info>',
$className,
$debug['unique_node_type'] ? '<comment>uniquely mapped</comment> ' : '',
$debug['node_type']
));
}
}

return 0;
}
Expand Down
24 changes: 11 additions & 13 deletions lib/Doctrine/ODM/PHPCR/Tools/Helper/UniqueNodeTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Provides unique node type mapping verification.
Expand All @@ -31,17 +30,18 @@ class UniqueNodeTypeHelper
/**
* Check each mapped PHPCR-ODM document for the given document manager,
* throwing an exception if any document is set to use a unique node
* type but the node type is re-used. If an OutputInterface is provided,
* write some basic information to it.
* type but the node type is re-used. Returns an array of debug information.
*
* @param DocumentManagerInterface $documentManager The document manager to check mappings for.
* @param OutputInterface $output If provided, output will be written here.
*
* @return array
*
* @throws MappingException
*/
public static function checkNodeTypeMappings(DocumentManagerInterface $documentManager, OutputInterface $output = null)
public function checkNodeTypeMappings(DocumentManagerInterface $documentManager)
{
$knownNodeTypes = array();
$debugInformation = array();
$allMetadata = $documentManager->getMetadataFactory()->getAllMetadata();

foreach ($allMetadata as $classMetadata) {
Expand All @@ -56,14 +56,12 @@ public static function checkNodeTypeMappings(DocumentManagerInterface $documentM

$knownNodeTypes[$classMetadata->getNodeType()] = $classMetadata->name;

if (!is_null($output)) {
$output->writeln(sprintf(
'The document <info>%s</info> uses %snode type <info>%s</info>',
$classMetadata->name,
$classMetadata->hasUniqueNodeType() ? '<comment>uniquely mapped</comment> ' : '',
$classMetadata->getNodeType()
));
}
$debugInformation[$classMetadata->name] = array(
'unique_node_type' => $classMetadata->hasUniqueNodeType(),
'node_type' => $classMetadata->getNodeType()
);
}

return $debugInformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function testCheckNodeTypeMappingsWithDuplicate()
$metadataC
));

UniqueNodeTypeHelper::checkNodeTypeMappings($documentManager);
$uniqueNodeTypeHelper = new UniqueNodeTypeHelper();
$uniqueNodeTypeHelper->checkNodeTypeMappings($documentManager);
}

/**
Expand All @@ -93,6 +94,7 @@ public function testCheckNodeTypeMappingsWithoutDuplicate()
$metadataC
));

UniqueNodeTypeHelper::checkNodeTypeMappings($documentManager);
$uniqueNodeTypeHelper = new UniqueNodeTypeHelper();
$uniqueNodeTypeHelper->checkNodeTypeMappings($documentManager);
}
}

0 comments on commit 0b86153

Please sign in to comment.