From 34946d715902b6bf1374bedb1dafe3d18d472739 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Thu, 11 Jun 2015 11:55:39 +0200 Subject: [PATCH] cleaned code --- composer.json | 8 +- .../Test/Fixture/DBUnitFixtureXML.php | 183 +++++++----------- 2 files changed, 76 insertions(+), 115 deletions(-) diff --git a/composer.json b/composer.json index f7892102..d47983ba 100644 --- a/composer.json +++ b/composer.json @@ -42,11 +42,5 @@ "branch-alias": { "dev-master": "1.3-dev" } - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/danrot/jackalope.git" - } - ] + } } diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index b861fe0a..17eb6b57 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -47,16 +47,16 @@ class DBUnitFixtureXML extends XMLDocument private $rootNodes; /** - * @param string $file - file path - * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php + * @param string $file - file path + * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php */ public function __construct($file, $options = null) { parent::__construct($file, $options); - $this->tables = array(); - $this->ids = array(); - $this->references = array(); + $this->tables = array(); + $this->ids = array(); + $this->references = array(); $this->expectedNodes = array(); } @@ -65,16 +65,13 @@ public function addDataset() $this->appendChild($this->createElement('dataset')); // purge binary in case no binary properties are in fixture - $this->ensureTableExists( - 'phpcr_binarydata', - array( - 'node_id', - 'property_name', - 'workspace_name', - 'idx', - 'data', - ) - ); + $this->ensureTableExists('phpcr_binarydata', array( + 'node_id', + 'property_name', + 'workspace_name', + 'idx', + 'data', + )); return $this; } @@ -102,7 +99,7 @@ public function addNamespaces(array $namespaces) * * If the root node is not called jcr:root, autogenerate a root node. * - * @param string $workspaceName + * @param string $workspaceName * @param \DOMNodeList $nodes * * @return DBUnitFixtureXML @@ -117,9 +114,7 @@ public function addNodes($workspaceName, \DOMNodeList $nodes) $this->rootNodes[$workspaceName] = true; } - $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML( - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml' - ); + $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml'); foreach ($srcDom->load()->getNodes() as $node) { $this->addNode($workspaceName, $node); } @@ -137,31 +132,31 @@ public function addRootNode($workspaceName = 'default') $this->ids[$uuid] = self::$idCounter++; return $this->addRow('phpcr_nodes', array( - 'id' => $this->ids[$uuid], - 'path' => '/', - 'parent' => '', - 'local_name' => '', - 'namespace' => '', - 'workspace_name'=> $workspaceName, - 'identifier' => $uuid, - 'type' => 'nt:unstructured', - 'props' => '' - . '', - 'depth' => 0, - 'sort_order' => 0, + 'id' => $this->ids[$uuid], + 'path' => '/', + 'parent' => '', + 'local_name' => '', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => 'nt:unstructured', + 'props' => '' + . '', + 'depth' => 0, + 'sort_order' => 0, )); } @@ -169,7 +164,7 @@ public function addNode($workspaceName, \DOMElement $node) { $properties = $this->getAttributes($node); $uuid = isset($properties['jcr:uuid']['value'][0]) - ? (string)$properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); + ? (string) $properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); $this->ids[$uuid] = $id = isset($this->expectedNodes[$uuid]) ? $this->expectedNodes[$uuid] : self::$idCounter++; @@ -189,25 +184,23 @@ public function addNode($workspaceName, \DOMElement $node) throw new \InvalidArgumentException('"' . $propertyData['type'] . '" is not a valid JCR type.'); } - $phpcrNode->appendChild( - $this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode) - ); + $phpcrNode->appendChild($this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode)); } list($parentPath, $childPath) = $this->getPath($node); $namespace = ''; - $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); + $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); if (count($parts = explode(':', $name, 2)) == 2) { list($namespace, $name) = $parts; } if ($namespace == 'jcr' && $name == 'root') { - $id = 1; - $childPath = '/'; + $id = 1; + $childPath = '/'; $parentPath = ''; - $name = ''; - $namespace = ''; + $name = ''; + $namespace = ''; } if (isset($properties['jcr:mixinTypes']) @@ -216,22 +209,19 @@ public function addNode($workspaceName, \DOMElement $node) $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id, $uuid); } - $this->addRow( - 'phpcr_nodes', - array( - 'id' => $id, - 'path' => $childPath, - 'parent' => $parentPath, - 'local_name' => $name, - 'namespace' => $namespace, - 'workspace_name' => $workspaceName, - 'identifier' => $uuid, - 'type' => $properties['jcr:primaryType']['value'][0], - 'props' => $dom->saveXML(), - 'depth' => PathHelper::getPathDepth($childPath), - 'sort_order' => $id - 2, - ) - ); + $this->addRow('phpcr_nodes', array( + 'id' => $id, + 'path' => $childPath, + 'parent' => $parentPath, + 'local_name' => $name, + 'namespace' => $namespace, + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => $properties['jcr:primaryType']['value'][0], + 'props' => $dom->saveXML(), + 'depth' => PathHelper::getPathDepth($childPath), + 'sort_order' => $id - 2, + )); return $this; } @@ -239,7 +229,7 @@ public function addNode($workspaceName, \DOMElement $node) public function addReferences() { foreach ($this->references as $type => $references) { - $table = 'phpcr_nodes_' . $type . 's'; + $table = 'phpcr_nodes_'.$type.'s'; // make sure we have the references even if there is not a single entry in it to have it truncated $this->ensureTableExists($table, array('source_id', 'source_property_name', 'target_id')); @@ -287,10 +277,7 @@ public function getChildAttribute(\DOMElement $node) $isMultiValue = false; if ($name == 'jcr:mixinTypes' || count($values) > 1 - || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS( - $this->namespaces['sv'], - 'multiple' - ) == 'true') + || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS($this->namespaces['sv'], 'multiple') == 'true') ) { $isMultiValue = true; } @@ -307,31 +294,14 @@ public function createPropertyNode($workspaceName, $propertyName, $propertyData, $binaryDataIdx = 0; foreach ($propertyData['value'] as $value) { - $propertyNode->appendChild( - $this->createValueNodeByType( - $workspaceName, - $propertyData['type'], - $value, - $id, - $propertyName, - $binaryDataIdx++, - $dom - ) - ); + $propertyNode->appendChild($this->createValueNodeByType($workspaceName, $propertyData['type'], $value, $id, $propertyName, $binaryDataIdx++, $dom)); } return $propertyNode; } - public function createValueNodeByType( - $workspaceName, - $type, - $value, - $id, - $propertyName, - $binaryDataIdx, - \DOMDocument $dom - ) { + public function createValueNodeByType($workspaceName, $type, $value, $id, $propertyName, $binaryDataIdx, \DOMDocument $dom) + { $length = is_scalar($value) ? strlen($value) : null; switch ($type) { case 'binary': @@ -359,9 +329,9 @@ public function createValueNodeByType( } // do not repeat references $this->references[$type][$value][$id . $propertyName . $targetId] = array( - 'source_id' => $id, + 'source_id' => $id, 'source_property_name' => $propertyName, - 'target_id' => $targetId, + 'target_id' => $targetId, ); break; } @@ -409,10 +379,10 @@ public function getPath(\DOMElement $node) } /** - * @param int $id + * @param int $id * @param string $propertyName * @param string $workspaceName - * @param int $idx + * @param int $idx * @param string $data * * @return int - length of base64 decoded string @@ -421,16 +391,13 @@ public function addBinaryNode($id, $propertyName, $workspaceName, $idx, $data) { $data = base64_decode($data); - $this->addRow( - 'phpcr_binarydata', - array( - 'node_id' => $id, - 'property_name' => $propertyName, - 'workspace_name' => $workspaceName, - 'idx' => $idx, - 'data' => $data, - ) - ); + $this->addRow('phpcr_binarydata', array( + 'node_id' => $id, + 'property_name' => $propertyName, + 'workspace_name' => $workspaceName, + 'idx' => $idx, + 'data' => $data, + )); return strlen($data); }