Skip to content

Commit 000848f

Browse files
small cleanup
1 parent f212d3f commit 000848f

25 files changed

+210
-93
lines changed

bin/phpcr

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env php
22
<?php
33

4+
use Symfony\Component\Console\Application;
5+
use Symfony\Component\Console\Helper\HelperSet;
6+
use PHPCR\Util\Console\Command;
7+
48
if (!class_exists('\Symfony\Component\Console\Application')) {
59
if (is_file(__DIR__.'/../vendor/autoload.php')) {
610
require __DIR__.'/../vendor/autoload.php';
@@ -19,7 +23,7 @@ $helperSet = null;
1923
if (file_exists($configFile)) {
2024
if (!is_readable($configFile)) {
2125
trigger_error(
22-
'Configuration file [' . $configFile . '] does not have read permission.', E_USER_ERROR
26+
"Configuration file [$configFile] does not have read permission.", E_USER_ERROR
2327
);
2428
}
2529

@@ -33,29 +37,32 @@ if (file_exists($configFile)) {
3337
}
3438
} else {
3539
trigger_error(
36-
'Configuration file [' . $configFile . '] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration', E_USER_ERROR
40+
"Configuration file [$configFile] does not exist. See https://github.com/doctrine/phpcr-odm/wiki/Command-line-tool-configuration", E_USER_ERROR
3741
);
3842
}
3943

40-
$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
44+
$helperSet = $helperSet ?: new HelperSet();
45+
46+
$cli = new Application('PHPCR Command Line Interface', '0.1');
4147

42-
$cli = new \Symfony\Component\Console\Application('PHPCR Command Line Interface', '0.1');
4348
$cli->setCatchExceptions(true);
4449
$cli->setHelperSet($helperSet);
50+
4551
$cli->addCommands(array(
46-
new \PHPCR\Util\Console\Command\NodeDumpCommand(),
47-
new \PHPCR\Util\Console\Command\NodeMoveCommand(),
48-
new \PHPCR\Util\Console\Command\NodeRemoveCommand(),
49-
new \PHPCR\Util\Console\Command\NodeTouchCommand(),
50-
new \PHPCR\Util\Console\Command\NodesUpdateCommand(),
51-
new \PHPCR\Util\Console\Command\NodeTypeListCommand(),
52-
new \PHPCR\Util\Console\Command\NodeTypeRegisterCommand(),
53-
new \PHPCR\Util\Console\Command\WorkspaceCreateCommand(),
54-
new \PHPCR\Util\Console\Command\WorkspaceDeleteCommand(),
55-
new \PHPCR\Util\Console\Command\WorkspaceExportCommand(),
56-
new \PHPCR\Util\Console\Command\WorkspaceImportCommand(),
57-
new \PHPCR\Util\Console\Command\WorkspacePurgeCommand(),
58-
new \PHPCR\Util\Console\Command\WorkspaceQueryCommand(),
52+
new Command\NodeDumpCommand(),
53+
new Command\NodeMoveCommand(),
54+
new Command\NodeRemoveCommand(),
55+
new Command\NodeTouchCommand(),
56+
new Command\NodesUpdateCommand(),
57+
new Command\NodeTypeListCommand(),
58+
new Command\NodeTypeRegisterCommand(),
59+
new Command\WorkspaceCreateCommand(),
60+
new Command\WorkspaceDeleteCommand(),
61+
new Command\WorkspaceExportCommand(),
62+
new Command\WorkspaceImportCommand(),
63+
new Command\WorkspacePurgeCommand(),
64+
new Command\WorkspaceQueryCommand(),
5965
));
66+
6067
$cli->run();
6168

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"phpcr/phpcr": "~2.1.0",
3232
"symfony/console": "~2.3|~3.0"
3333
},
34+
"require-dev": {
35+
"ramsey/uuid": "^3.5"
36+
},
3437
"suggest": {
3538
"ramsey/uuid": "A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)."
3639
},

src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPCR\Util\Console\Command;
44

5+
use InvalidArgumentException;
6+
use PHPCR\RepositoryException;
57
use Symfony\Component\Console\Input\InputArgument;
68
use Symfony\Component\Console\Input\InputOption;
7-
use Symfony\Component\Console\Command\Command;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Output\OutputInterface;
1011
use PHPCR\SessionInterface;
@@ -62,15 +63,15 @@ protected function configure()
6263

6364
/**
6465
* {@inheritDoc}
66+
*
67+
* @throws InvalidArgumentException
6568
*/
6669
protected function execute(InputInterface $input, OutputInterface $output)
6770
{
6871
$definitions = $input->getArgument('cnd-file');
6972

7073
if (count($definitions) == 0) {
71-
throw new \InvalidArgumentException(
72-
'At least one definition (i.e. file or folder) must be specified'
73-
);
74+
throw new InvalidArgumentException('At least one definition (i.e. file or folder) must be specified');
7475
}
7576

7677
$allowUpdate = $input->getOption('allow-update');
@@ -99,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
99100
* @param string $cnd the compact namespace and node type definition in string form
100101
* @param bool $allowUpdate whether to allow updating existing node types.
101102
*
102-
* @throws \PHPCR\RepositoryException on other errors
103+
* @throws RepositoryException on other errors
103104
*/
104105
protected function updateFromCnd(OutputInterface $output, SessionInterface $session, $cnd, $allowUpdate)
105106
{
@@ -124,6 +125,8 @@ protected function updateFromCnd(OutputInterface $output, SessionInterface $sess
124125
* @param array $definitions List of files of folders
125126
*
126127
* @return array Array of full paths to all the type node definition files.
128+
*
129+
* @throws InvalidArgumentException
127130
*/
128131
protected function getFilePaths($definitions)
129132
{
@@ -141,7 +144,7 @@ protected function getFilePaths($definitions)
141144
$filePath = sprintf('%s/%s', $definition, $file);
142145

143146
if (!is_readable($filePath)) {
144-
throw new \InvalidArgumentException(
147+
throw new InvalidArgumentException(
145148
sprintf("Node type definition file '<info>%s</info>' does not have read permissions.", $file)
146149
);
147150
}
@@ -150,7 +153,7 @@ protected function getFilePaths($definitions)
150153
}
151154
} else {
152155
if (!file_exists($definition)) {
153-
throw new \InvalidArgumentException(
156+
throw new InvalidArgumentException(
154157
sprintf("Node type definition file / folder '<info>%s</info>' does not exist.", $definition)
155158
);
156159
}

src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6161
return 1;
6262
}
6363

64-
$session->importXml(
64+
$session->importXML(
6565
$parentPath,
6666
$filename,
6767
ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW

src/PHPCR/Util/Console/Helper/PhpcrHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPCR\Util\Console\Helper;
44

5+
use Exception;
56
use Symfony\Component\Console\Output\OutputInterface;
67
use Symfony\Component\Console\Helper\Helper;
78
use PHPCR\NodeInterface;
@@ -177,7 +178,7 @@ protected function validateQueryLanguage($language)
177178
}
178179
}
179180

180-
throw new \Exception(sprintf(
181+
throw new Exception(sprintf(
181182
'Query language "%s" not supported, available query languages: %s',
182183
$language, implode(',', $langs)
183184
));

src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPCR\Util\Console\Helper\TreeDumper;
44

5+
use Exception;
56
use Symfony\Component\Console\Output\OutputInterface;
67
use PHPCR\ItemInterface;
78
use PHPCR\NodeInterface;
@@ -51,14 +52,16 @@ public function setShowFullPath($showFullPath)
5152
* Print information about the visited node.
5253
*
5354
* @param ItemInterface $item the node to visit
55+
*
56+
* @throws Exception
5457
*/
5558
public function visit(ItemInterface $item)
5659
{
5760
if (! $item instanceof NodeInterface) {
58-
throw new \Exception("Internal error: did not expect to visit a non-node object: $item");
61+
throw new Exception("Internal error: did not expect to visit a non-node object: $item");
5962
}
6063

61-
if ($item->getDepth() == 0) {
64+
if ($item->getDepth() === 0) {
6265
$name = 'ROOT';
6366
} elseif ($this->showFullPath) {
6467
$name = $item->getPath();

src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPCR\Util\Console\Helper\TreeDumper;
44

5+
use Exception;
56
use Symfony\Component\Console\Output\OutputInterface;
67
use PHPCR\ItemInterface;
78
use PHPCR\PropertyInterface;
@@ -30,7 +31,7 @@ class ConsoleDumperPropertyVisitor extends ConsoleDumperItemVisitor
3031
* Instantiate property visitor
3132
*
3233
* @param OutputInterface $output
33-
* @param int $maxLineLength
34+
* @param array $options
3435
*/
3536
public function __construct(OutputInterface $output, $options = array())
3637
{
@@ -49,11 +50,13 @@ public function __construct(OutputInterface $output, $options = array())
4950
* Print information about this property
5051
*
5152
* @param ItemInterface $item the property to visit
53+
*
54+
* @throws Exception
5255
*/
5356
public function visit(ItemInterface $item)
5457
{
5558
if (! $item instanceof PropertyInterface) {
56-
throw new \Exception(sprintf('Internal error: did not expect to visit a non-property object: %s', is_object($item) ? get_class($item) : $item));
59+
throw new Exception(sprintf('Internal error: did not expect to visit a non-property object: %s', is_object($item) ? get_class($item) : $item));
5760
}
5861

5962
$value = $item->getString();

src/PHPCR/Util/Console/Helper/TreeDumper/SystemNodeFilter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPCR\Util\Console\Helper\TreeDumper;
44

55
use PHPCR\ItemInterface;
6+
use PHPCR\RepositoryException;
67
use PHPCR\Util\TreeWalkerFilterInterface;
78
use PHPCR\Util\NodeHelper;
89

@@ -19,6 +20,8 @@ class SystemNodeFilter implements TreeWalkerFilterInterface
1920
* @param ItemInterface $item
2021
*
2122
* @return boolean
23+
*
24+
* @throws RepositoryException
2225
*/
2326
public function mustVisit(ItemInterface $item)
2427
{

src/PHPCR/Util/NodeHelper.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
namespace PHPCR\Util;
44

5+
use InvalidArgumentException;
6+
use PHPCR\ItemExistsException;
57
use PHPCR\ItemInterface;
8+
use PHPCR\Lock\LockException;
69
use PHPCR\NodeInterface;
10+
use PHPCR\NodeType\ConstraintViolationException;
11+
use PHPCR\PathNotFoundException;
712
use PHPCR\PropertyInterface;
813
use PHPCR\SessionInterface;
914
use PHPCR\RepositoryException;
1015
use PHPCR\ItemNotFoundException;
1116
use PHPCR\NamespaceException;
17+
use PHPCR\Version\VersionException;
1218

1319
/**
1420
* Helper with only static methods to work with PHPCR nodes
@@ -35,6 +41,14 @@ private function __construct()
3541
* @param string $path full path, like /content/jobs/data
3642
*
3743
* @return NodeInterface the last node of the path, i.e. data
44+
*
45+
* @throws InvalidArgumentException
46+
* @throws RepositoryException
47+
* @throws PathNotFoundException
48+
* @throws ItemExistsException
49+
* @throws LockException
50+
* @throws ConstraintViolationException
51+
* @throws VersionException
3852
*/
3953
public static function createPath(SessionInterface $session, $path)
4054
{
@@ -65,6 +79,8 @@ public static function createPath(SessionInterface $session, $path)
6579
* @param SessionInterface $session the session to remove all children of
6680
* the root node
6781
*
82+
* @throws RepositoryException
83+
*
6884
* @see isSystemItem
6985
*/
7086
public static function purgeWorkspace(SessionInterface $session)
@@ -91,6 +107,8 @@ public static function purgeWorkspace(SessionInterface $session)
91107
*
92108
* @param SessionInterface $session
93109
*
110+
* @throws RepositoryException
111+
*
94112
* @deprecated
95113
*/
96114
public static function deleteAllNodes(SessionInterface $session)
@@ -106,6 +124,8 @@ public static function deleteAllNodes(SessionInterface $session)
106124
* @param ItemInterface $item
107125
*
108126
* @return boolean true if $item is a system item, false otherwise
127+
*
128+
* @throws RepositoryException
109129
*/
110130
public static function isSystemItem(ItemInterface $item)
111131
{
@@ -133,6 +153,8 @@ public static function isSystemItem(ItemInterface $item)
133153
* @throws NamespaceException if a namespace prefix is provided in the
134154
* $nameHint which does not exist and this implementation performs
135155
* this validation immediately.
156+
*
157+
* @throws RepositoryException
136158
*/
137159
public static function generateAutoNodeName($usedNames, $namespaces, $defaultNamespace, $nameHint = null)
138160
{
@@ -150,15 +172,15 @@ public static function generateAutoNodeName($usedNames, $namespaces, $defaultNam
150172
* be in the empty namespace and the local part of the name will be
151173
* generated by the repository.
152174
*/
153-
if ('' === $nameHint || ':' == $nameHint || '{}' == $nameHint) {
175+
if ('' === $nameHint || ':' === $nameHint || '{}' === $nameHint) {
154176
return self::generateWithPrefix($usedNames, '');
155177
}
156178

157179
/*
158180
* "<i>somePrefix</i>:" where <i>somePrefix</i> is a syntactically
159181
* valid namespace prefix
160182
*/
161-
if (':' == $nameHint[strlen($nameHint)-1]
183+
if (':' === $nameHint[strlen($nameHint)-1]
162184
&& substr_count($nameHint, ':') === 1
163185
&& preg_match('#^[a-zA-Z][a-zA-Z0-9]*:$#', $nameHint)
164186
) {
@@ -175,8 +197,8 @@ public static function generateAutoNodeName($usedNames, $namespaces, $defaultNam
175197
* namespace URI
176198
*/
177199
if (strlen($nameHint) > 2
178-
&& '{' == $nameHint[0]
179-
&& '}' == $nameHint[strlen($nameHint)-1]
200+
&& '{' === $nameHint[0]
201+
&& '}' === $nameHint[strlen($nameHint)-1]
180202
&& filter_var(substr($nameHint, 1, -1), FILTER_VALIDATE_URL)
181203
) {
182204
$prefix = array_search(substr($nameHint, 1, -1), $namespaces);
@@ -328,7 +350,7 @@ public static function calculateOrderBefore(array $old, array $new)
328350
*
329351
* @return array The updated $nodes array with new order
330352
*
331-
* @throws \PHPCR\ItemNotFoundException if $srcChildRelPath or $destChildRelPath are not found in $nodes
353+
* @throws ItemNotFoundException if $srcChildRelPath or $destChildRelPath are not found in $nodes
332354
*/
333355
public static function orderBeforeArray($name, $destination, $list)
334356
{

src/PHPCR/Util/PathHelper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private function __construct()
4747
public static function assertValidAbsolutePath($path, $destination = false, $throw = true, $namespacePrefixes = false)
4848
{
4949
if ((!is_string($path) && !is_numeric($path))
50-
|| strlen($path) == 0
50+
|| strlen($path) === 0
5151
|| '/' !== $path[0]
5252
|| strlen($path) > 1 && '/' === $path[strlen($path) - 1]
5353
|| preg_match('-//|/\./|/\.\./-', $path)
@@ -94,7 +94,7 @@ public static function assertValidAbsolutePath($path, $destination = false, $thr
9494
*/
9595
public static function assertValidLocalName($name, $throw = true)
9696
{
97-
if ('.' == $name || '..' == $name) {
97+
if ('.' === $name || '..' === $name) {
9898
return self::error("Name may not be parent or self identifier: $name", $throw);
9999
}
100100

@@ -262,6 +262,8 @@ public static function getParentPath($path)
262262
* @param string $path a valid absolute path, like /content/jobs/data
263263
*
264264
* @return string the name, that is the string after the last "/"
265+
*
266+
* @throws RepositoryException
265267
*/
266268
public static function getNodeName($path)
267269
{
@@ -283,6 +285,8 @@ public static function getNodeName($path)
283285
* @param string $path a valid absolute path
284286
*
285287
* @return string The localname
288+
*
289+
* @throws RepositoryException
286290
*/
287291
public static function getLocalNodeName($path)
288292
{

0 commit comments

Comments
 (0)