diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 98bf6419..0f89ba68 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -40,3 +40,16 @@ jobs: uses: docker://oskarstark/phpstan-ga:1.8.0 with: args: analyze --no-progress -c phpstan.tests.neon.dist + + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --dry-run --diff diff --git a/.gitignore b/.gitignore index bb6966fc..35e5af6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ cli-config.php - +.php-cs-fixer.cache vendor/ composer.phar -composer.lock \ No newline at end of file +composer.lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..92bc7484 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,18 @@ +in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ->name('*.php') +; + +$config = new PhpCsFixer\Config(); + +return $config + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'single_line_throw' => false, + ]) + ->setFinder($finder) +; diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 5e45ebb5..00000000 --- a/.styleci.yml +++ /dev/null @@ -1,6 +0,0 @@ -preset: recommended - -enabled: - - no_useless_else -disabled: - - align_double_arrow diff --git a/composer.json b/composer.json index e4e125dc..d76537da 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "require-dev": { "ramsey/uuid": "^3.5", "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", - "phpstan/phpstan": "^1.9" + "phpstan/phpstan": "^1.9", + "friendsofphp/php-cs-fixer": "^3.40" }, "suggest": { "ramsey/uuid": "A library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)." diff --git a/src/PHPCR/Util/CND/Exception/ParserException.php b/src/PHPCR/Util/CND/Exception/ParserException.php index a08d67e4..5652ee1f 100644 --- a/src/PHPCR/Util/CND/Exception/ParserException.php +++ b/src/PHPCR/Util/CND/Exception/ParserException.php @@ -19,7 +19,7 @@ public function __construct(TokenQueue $queue, $msg) // construct a lookup of the next tokens $lookup = ''; - for ($i = 1; $i <= 5; $i++) { + for ($i = 1; $i <= 5; ++$i) { if ($queue->isEof()) { break; } diff --git a/src/PHPCR/Util/CND/Parser/AbstractParser.php b/src/PHPCR/Util/CND/Parser/AbstractParser.php index e01aae62..a7f3aba3 100644 --- a/src/PHPCR/Util/CND/Parser/AbstractParser.php +++ b/src/PHPCR/Util/CND/Parser/AbstractParser.php @@ -34,7 +34,7 @@ abstract class AbstractParser * Return false otherwise. * * @param int $type The expected token type - * @param null|string $data The expected data or null + * @param string|null $data The expected data or null * @param bool $ignoreCase whether to do string comparisons case insensitive or sensitive * * @return bool @@ -65,8 +65,7 @@ protected function checkToken($type, $data = null, $ignoreCase = false) /** * Check if the token data is one of the elements of the data array. * - * @param int $type - * @param array $data + * @param int $type * * @return bool */ @@ -86,11 +85,11 @@ protected function checkTokenIn($type, array $data, $ignoreCase = false) * otherwise throw an exception. * * @param int $type The expected token type - * @param null|string $data The expected token data or null - * - * @throws ParserException + * @param string|null $data The expected token data or null * * @return Token + * + * @throws ParserException */ protected function expectToken($type, $data = null) { @@ -110,7 +109,7 @@ protected function expectToken($type, $data = null) * return false. * * @param int $type The expected token type - * @param null|string $data The expected token data or null + * @param string|null $data The expected token data or null * * @return bool|Token */ diff --git a/src/PHPCR/Util/CND/Parser/CndParser.php b/src/PHPCR/Util/CND/Parser/CndParser.php index dab5dc9e..59249d78 100644 --- a/src/PHPCR/Util/CND/Parser/CndParser.php +++ b/src/PHPCR/Util/CND/Parser/CndParser.php @@ -35,30 +35,30 @@ class CndParser extends AbstractParser { // node type attributes - private $ORDERABLE = ['o', 'ord', 'orderable']; //, 'variant' => true); - private $MIXIN = ['m', 'mix', 'mixin']; //, 'variant' => true); - private $ABSTRACT = ['a', 'abs', 'abstract']; //, 'variant' => true); - private $NOQUERY = ['noquery', 'nq']; //, 'variant' => false); - private $QUERY = ['query', 'q']; //, 'variant' => false); - private $PRIMARYITEM = ['primaryitem', '!']; //, 'variant' => false); + private $ORDERABLE = ['o', 'ord', 'orderable']; // , 'variant' => true); + private $MIXIN = ['m', 'mix', 'mixin']; // , 'variant' => true); + private $ABSTRACT = ['a', 'abs', 'abstract']; // , 'variant' => true); + private $NOQUERY = ['noquery', 'nq']; // , 'variant' => false); + private $QUERY = ['query', 'q']; // , 'variant' => false); + private $PRIMARYITEM = ['primaryitem', '!']; // , 'variant' => false); // common for properties and child definitions - private $PRIMARY = ['!', 'pri', 'primary']; //, 'variant' => true), - private $AUTOCREATED = ['a', 'aut', 'autocreated']; //, 'variant' => true), - private $MANDATORY = ['m', 'man', 'mandatory']; //, 'variant' => true), - private $PROTECTED = ['p', 'pro', 'protected']; //, 'variant' => true), + private $PRIMARY = ['!', 'pri', 'primary']; // , 'variant' => true), + private $AUTOCREATED = ['a', 'aut', 'autocreated']; // , 'variant' => true), + private $MANDATORY = ['m', 'man', 'mandatory']; // , 'variant' => true), + private $PROTECTED = ['p', 'pro', 'protected']; // , 'variant' => true), private $OPV = ['COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT']; // property type attributes - private $MULTIPLE = ['*', 'mul', 'multiple']; //, 'variant' => true), - private $QUERYOPS = ['qop', 'queryops']; //, 'variant' => true), // Needs special handling ! - private $NOFULLTEXT = ['nof', 'nofulltext']; //, 'variant' => true), - private $NOQUERYORDER = ['nqord', 'noqueryorder']; //, 'variant' => true), + private $MULTIPLE = ['*', 'mul', 'multiple']; // , 'variant' => true), + private $QUERYOPS = ['qop', 'queryops']; // , 'variant' => true), // Needs special handling ! + private $NOFULLTEXT = ['nof', 'nofulltext']; // , 'variant' => true), + private $NOQUERYORDER = ['nqord', 'noqueryorder']; // , 'variant' => true), // child node attributes // multiple is actually a jackrabbit specific synonym for sns // http://www.mail-archive.com/users@jackrabbit.apache.org/msg19268.html - private $SNS = ['*', 'sns', 'multiple']; //, 'variant' => true), + private $SNS = ['*', 'sns', 'multiple']; // , 'variant' => true), /** * @var NodeTypeManagerInterface @@ -75,9 +75,6 @@ class CndParser extends AbstractParser */ protected $nodeTypes = []; - /** - * @param NodeTypeManagerInterface $ntm - */ public function __construct(NodeTypeManagerInterface $ntm) { $this->ntm = $ntm; @@ -130,7 +127,7 @@ private function parse(ReaderInterface $reader) return [ 'namespaces' => $this->namespaces, - 'nodeTypes' => $this->nodeTypes, + 'nodeTypes' => $this->nodeTypes, ]; } @@ -350,7 +347,7 @@ protected function parsePropDef(NodeTypeTemplateInterface $nodeType) // Next token is '<' and two token later it's not '=', i.e. not 'tokenQueue->peek(); $next2 = $this->tokenQueue->peek(2); - if ($next1 && $next1->getData() === '<' && (!$next2 || $next2->getData() !== '=')) { + if ($next1 && '<' === $next1->getData() && (!$next2 || '=' !== $next2->getData())) { $this->parseValueConstraints($property); } } @@ -678,7 +675,7 @@ protected function parseCndString() $type = $token->getType(); $data = $token->getData(); - if ($type === Token::TK_STRING) { + if (Token::TK_STRING === $type) { $string = substr($data, 1, -1); $this->tokenQueue->next(); @@ -686,13 +683,13 @@ protected function parseCndString() } // If it's not an identifier or a symbol allowed in a string, break - if ($type !== Token::TK_IDENTIFIER && $type !== Token::TK_SYMBOL - || ($type === Token::TK_SYMBOL && $data !== '_' && $data !== ':')) { + if (Token::TK_IDENTIFIER !== $type && Token::TK_SYMBOL !== $type + || (Token::TK_SYMBOL === $type && '_' !== $data && ':' !== $data)) { break; } // Detect spaces (an identifier cannot be followed by an identifier as it would have been read as a single token) - if ($type === Token::TK_IDENTIFIER && $lastType === Token::TK_IDENTIFIER) { + if (Token::TK_IDENTIFIER === $type && Token::TK_IDENTIFIER === $lastType) { break; } @@ -702,7 +699,7 @@ protected function parseCndString() $lastType = $type; } - if ($string === '') { + if ('' === $string) { throw new ParserException($this->tokenQueue, sprintf("Expected CND string, found '%s': ", $this->tokenQueue->peek()->getData())); } @@ -752,10 +749,10 @@ protected function parseQueryOperator() switch ($data) { case '<': - $op = ($nextData === '>' ? '>=' : ($nextData === '=' ? '<=' : '<')); + $op = ('>' === $nextData ? '>=' : ('=' === $nextData ? '<=' : '<')); break; case '>': - $op = ($nextData === '=' ? '>=' : '>'); + $op = ('=' === $nextData ? '>=' : '>'); break; case '=': $op = '='; @@ -766,9 +763,9 @@ protected function parseQueryOperator() } // Consume the correct number of tokens - if ($op === 'LIKE' || strlen($op) === 1) { + if ('LIKE' === $op || 1 === strlen($op)) { $this->tokenQueue->next(); - } elseif (strlen($op) === 2) { + } elseif (2 === strlen($op)) { $this->tokenQueue->next(); $this->tokenQueue->next(); } diff --git a/src/PHPCR/Util/CND/Reader/BufferReader.php b/src/PHPCR/Util/CND/Reader/BufferReader.php index e38c00df..20db884d 100644 --- a/src/PHPCR/Util/CND/Reader/BufferReader.php +++ b/src/PHPCR/Util/CND/Reader/BufferReader.php @@ -115,6 +115,7 @@ public function currentChar() public function isEof() { $currentChar = $this->currentChar(); + // substr after end of string returned false in PHP 5 and returns '' since PHP 7 return in_array($currentChar, [$this->getEofMarker(), false, ''], true) || $this->startPos > strlen($this->buffer) @@ -129,12 +130,12 @@ public function isEof() public function forward() { if ($this->forwardPos < strlen($this->buffer)) { - $this->forwardPos++; - $this->nextCurCol++; + ++$this->forwardPos; + ++$this->nextCurCol; } - if ($this->current() === "\n") { - $this->nextCurLine++; + if ("\n" === $this->current()) { + ++$this->nextCurLine; $this->nextCurCol = 1; } diff --git a/src/PHPCR/Util/CND/Scanner/AbstractScanner.php b/src/PHPCR/Util/CND/Scanner/AbstractScanner.php index f61f0dd1..35eb208f 100644 --- a/src/PHPCR/Util/CND/Scanner/AbstractScanner.php +++ b/src/PHPCR/Util/CND/Scanner/AbstractScanner.php @@ -30,8 +30,6 @@ public function resetQueue() } /** - * @param Token $token - * * @return Token|void */ public function applyFilters(Token $token) diff --git a/src/PHPCR/Util/CND/Scanner/Context/ScannerContext.php b/src/PHPCR/Util/CND/Scanner/Context/ScannerContext.php index a9ea48a9..f9855dd1 100644 --- a/src/PHPCR/Util/CND/Scanner/Context/ScannerContext.php +++ b/src/PHPCR/Util/CND/Scanner/Context/ScannerContext.php @@ -143,9 +143,6 @@ public function getWhitespaces() return $this->whitespaces; } - /** - * @param TokenFilterInterface $filter - */ public function addTokenFilter(TokenFilterInterface $filter) { $this->tokenFilters[] = $filter; diff --git a/src/PHPCR/Util/CND/Scanner/GenericScanner.php b/src/PHPCR/Util/CND/Scanner/GenericScanner.php index 76ccecd5..18608540 100644 --- a/src/PHPCR/Util/CND/Scanner/GenericScanner.php +++ b/src/PHPCR/Util/CND/Scanner/GenericScanner.php @@ -21,8 +21,6 @@ class GenericScanner extends AbstractScanner /** * Scan the given reader and construct a TokenQueue composed of GenericToken. * - * @param ReaderInterface $reader - * * @return TokenQueue */ public function scan(ReaderInterface $reader) @@ -55,8 +53,6 @@ public function scan(ReaderInterface $reader) /** * Detect and consume whitespaces. * - * @param ReaderInterface $reader - * * @return bool */ protected function consumeSpaces(ReaderInterface $reader) @@ -81,17 +77,15 @@ protected function consumeSpaces(ReaderInterface $reader) /** * Detect and consume newlines. * - * @param ReaderInterface $reader - * * @return bool */ protected function consumeNewLine(ReaderInterface $reader) { - if ($reader->currentChar() === "\n") { + if ("\n" === $reader->currentChar()) { $token = new GenericToken(GenericToken::TK_NEWLINE, "\n"); $this->addToken($reader, $token); - while ($reader->forward() === "\n") { + while ("\n" === $reader->forward()) { $reader->consume(); $reader->forward(); } @@ -106,11 +100,9 @@ protected function consumeNewLine(ReaderInterface $reader) /** * Detect and consume strings. * - * @param ReaderInterface $reader + * @return bool * * @throws ScannerException - * - * @return bool */ protected function consumeString(ReaderInterface $reader) { @@ -118,7 +110,7 @@ protected function consumeString(ReaderInterface $reader) if (in_array($curDelimiter, $this->context->getStringDelimiters())) { $char = $reader->forwardChar(); while ($char !== $curDelimiter) { - if ($char === "\n") { + if ("\n" === $char) { throw new ScannerException($reader, 'Newline detected in string'); } @@ -138,8 +130,6 @@ protected function consumeString(ReaderInterface $reader) /** * Detect and consume comments. * - * @param ReaderInterface $reader - * * @return bool */ protected function consumeComments(ReaderInterface $reader) @@ -154,11 +144,9 @@ protected function consumeComments(ReaderInterface $reader) /** * Detect and consume block comments. * - * @param ReaderInterface $reader + * @return bool * * @throws ScannerException - * - * @return bool */ protected function consumeBlockComments(ReaderInterface $reader) { @@ -166,7 +154,7 @@ protected function consumeBlockComments(ReaderInterface $reader) foreach ($this->context->getBlockCommentDelimiters() as $beginDelim => $endDelim) { if ($nextChar === $beginDelim[0]) { // Lookup the start delimiter - for ($i = 1; $i <= strlen($beginDelim); $i++) { + for ($i = 1; $i <= strlen($beginDelim); ++$i) { $reader->forward(); } if ($reader->current() === $beginDelim) { @@ -175,7 +163,7 @@ protected function consumeBlockComments(ReaderInterface $reader) while (!$reader->isEof()) { if ($nextChar === $endDelim[0]) { - for ($i = 1; $i <= strlen($endDelim); $i++) { + for ($i = 1; $i <= strlen($endDelim); ++$i) { $reader->forward(); } @@ -207,8 +195,6 @@ protected function consumeBlockComments(ReaderInterface $reader) /** * Detect and consume line comments. * - * @param ReaderInterface $reader - * * @return bool */ protected function consumeLineComments(ReaderInterface $reader) @@ -216,14 +202,14 @@ protected function consumeLineComments(ReaderInterface $reader) $nextChar = $reader->currentChar(); foreach ($this->context->getLineCommentDelimiters() as $delimiter) { if ($delimiter && $nextChar === $delimiter[0]) { - for ($i = 1; $i <= strlen($delimiter); $i++) { + for ($i = 1; $i <= strlen($delimiter); ++$i) { $reader->forward(); } if ($reader->current() === $delimiter) { // consume to end of line $char = $reader->currentChar(); - while (!$reader->isEof() && $char !== "\n") { + while (!$reader->isEof() && "\n" !== $char) { $char = $reader->forwardChar(); } $token = new GenericToken(GenericToken::TK_COMMENT, $reader->consume()); @@ -245,8 +231,6 @@ protected function consumeLineComments(ReaderInterface $reader) /** * Detect and consume identifiers. * - * @param ReaderInterface $reader - * * @return bool */ protected function consumeIdentifiers(ReaderInterface $reader) @@ -270,8 +254,6 @@ protected function consumeIdentifiers(ReaderInterface $reader) /** * Detect and consume symbols. * - * @param ReaderInterface $reader - * * @return bool */ protected function consumeSymbols(ReaderInterface $reader) diff --git a/src/PHPCR/Util/CND/Scanner/GenericToken.php b/src/PHPCR/Util/CND/Scanner/GenericToken.php index 735de8c7..6d7e7e52 100644 --- a/src/PHPCR/Util/CND/Scanner/GenericToken.php +++ b/src/PHPCR/Util/CND/Scanner/GenericToken.php @@ -9,14 +9,14 @@ */ class GenericToken extends Token { - const TK_WHITESPACE = 0; - const TK_NEWLINE = 1; - const TK_STRING = 2; - const TK_COMMENT = 3; - const TK_IDENTIFIER = 4; - const TK_KEYWORD = 5; - const TK_SYMBOL = 6; - const TK_UNKNOWN = 99; + public const TK_WHITESPACE = 0; + public const TK_NEWLINE = 1; + public const TK_STRING = 2; + public const TK_COMMENT = 3; + public const TK_IDENTIFIER = 4; + public const TK_KEYWORD = 5; + public const TK_SYMBOL = 6; + public const TK_UNKNOWN = 99; public static function getTypeName($type) { diff --git a/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterChain.php b/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterChain.php index f24fdb6b..04020596 100644 --- a/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterChain.php +++ b/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterChain.php @@ -22,9 +22,7 @@ public function addFilter(TokenFilterInterface $filter) } /** - * @param Token $token - * - * @return Token | null + * @return Token|null */ public function filter(Token $token) { diff --git a/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterInterface.php b/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterInterface.php index 6acf162f..d61a7a29 100644 --- a/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterInterface.php +++ b/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenFilterInterface.php @@ -14,9 +14,7 @@ interface TokenFilterInterface /** * @abstract * - * @param Token $token - * - * @return Token | null + * @return Token|null */ public function filter(Token $token); } diff --git a/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenTypeFilter.php b/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenTypeFilter.php index 92683888..1bb953fa 100644 --- a/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenTypeFilter.php +++ b/src/PHPCR/Util/CND/Scanner/TokenFilter/TokenTypeFilter.php @@ -24,9 +24,7 @@ public function __construct($tokenType) } /** - * @param Token $token - * - * @return Token | null + * @return Token|null */ public function filter(Token $token) { diff --git a/src/PHPCR/Util/CND/Scanner/TokenQueue.php b/src/PHPCR/Util/CND/Scanner/TokenQueue.php index d1424d16..0904e24b 100644 --- a/src/PHPCR/Util/CND/Scanner/TokenQueue.php +++ b/src/PHPCR/Util/CND/Scanner/TokenQueue.php @@ -31,7 +31,7 @@ public function reset() public function isEof() { - return current($this->tokens) === false; + return false === current($this->tokens); } public function peek($offset = 0) @@ -52,7 +52,7 @@ public function peek($offset = 0) public function get($count = 1) { $item = null; - for ($i = 1; $i <= $count; $i++) { + for ($i = 1; $i <= $count; ++$i) { $item = $this->peek(); $this->next(); } diff --git a/src/PHPCR/Util/CND/Writer/CndWriter.php b/src/PHPCR/Util/CND/Writer/CndWriter.php index 2ab75382..154d8bdc 100644 --- a/src/PHPCR/Util/CND/Writer/CndWriter.php +++ b/src/PHPCR/Util/CND/Writer/CndWriter.php @@ -44,7 +44,7 @@ public function __construct(NamespaceRegistryInterface $ns) * @param NodeTypeTemplateInterface[] $nodeTypes * * @return string with declarations for all non-system namespaces and for - * all node types in that array. + * all node types in that array */ public function writeString(array $nodeTypes) { diff --git a/src/PHPCR/Util/Console/Command/BaseCommand.php b/src/PHPCR/Util/Console/Command/BaseCommand.php index 5fdd56e7..d1ff179f 100644 --- a/src/PHPCR/Util/Console/Command/BaseCommand.php +++ b/src/PHPCR/Util/Console/Command/BaseCommand.php @@ -51,10 +51,8 @@ protected function getPhpcrConsoleDumperHelper() /** * Ask a question with the question helper or the dialog helper for symfony < 2.5 compatibility. * - * @param InputInterface $input - * @param OutputInterface $output - * @param string $questionText - * @param string $default + * @param string $questionText + * @param string $default * * @return string */ @@ -72,10 +70,8 @@ protected function ask(InputInterface $input, OutputInterface $output, $question /** * Ask for confirmation with the question helper or the dialog helper for symfony < 2.5 compatibility. * - * @param InputInterface $input - * @param OutputInterface $output - * @param string $questionText - * @param bool $default + * @param string $questionText + * @param bool $default * * @return string */ diff --git a/src/PHPCR/Util/Console/Command/NodeDumpCommand.php b/src/PHPCR/Util/Console/Command/NodeDumpCommand.php index dcfbd686..0f6f434c 100644 --- a/src/PHPCR/Util/Console/Command/NodeDumpCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeDumpCommand.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Command; -use Exception; use PHPCR\ItemNotFoundException; use PHPCR\PathNotFoundException; use PHPCR\RepositoryException; @@ -52,7 +51,7 @@ protected function configure(): void /** * @throws InvalidArgumentException - * @throws Exception + * @throws \Exception * @throws RepositoryException */ protected function execute(InputInterface $input, OutputInterface $output): int @@ -72,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $options['max_line_length'] = $input->getOption('max_line_length'); if (null !== $options['ref_format'] && !in_array($options['ref_format'], ['uuid', 'path'])) { - throw new Exception('The ref-format option must be set to either "path" or "uuid"'); + throw new \Exception('The ref-format option must be set to either "path" or "uuid"'); } $walker = $dumperHelper->getTreeWalker($output, $options); diff --git a/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php b/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php index 0ee74319..a6083a1b 100644 --- a/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Command; -use InvalidArgumentException; use PHPCR\NodeInterface; use Symfony\Component\Console\Exception\InvalidArgumentException as CliInvalidArgumentException; use Symfony\Component\Console\Input\InputArgument; @@ -49,7 +48,7 @@ protected function configure(): void /** * @throws CliInvalidArgumentException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output): int { @@ -62,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ('/' === $path) { // even if we have only children, this will not work as we would // try to remove system nodes. - throw new InvalidArgumentException( + throw new \InvalidArgumentException( 'Can not delete root node (path "/"), please use the '. 'workspace:purge command instead to purge the whole workspace.' ); diff --git a/src/PHPCR/Util/Console/Command/NodeTouchCommand.php b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php index e3cd0f45..e4dca658 100644 --- a/src/PHPCR/Util/Console/Command/NodeTouchCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php @@ -132,11 +132,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $helper->processNode($output, $node, [ - 'setProp' => $setProp, - 'removeProp' => $removeProp, - 'addMixins' => $addMixins, + 'setProp' => $setProp, + 'removeProp' => $removeProp, + 'addMixins' => $addMixins, 'removeMixins' => $removeMixins, - 'dump' => $dump, + 'dump' => $dump, ]); $session->save(); diff --git a/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php b/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php index 0534b2cc..3e8485fe 100644 --- a/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Command; -use InvalidArgumentException; use PHPCR\NodeType\NodeTypeExistsException; use PHPCR\RepositoryException; use PHPCR\SessionInterface; @@ -17,7 +16,7 @@ * * See the link below for the cnd definition. * - * @link http://jackrabbit.apache.org/node-type-notation.html + * @see http://jackrabbit.apache.org/node-type-notation.html * * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004 * @license http://opensource.org/licenses/MIT MIT License @@ -59,14 +58,14 @@ protected function configure(): void } /** - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output): int { $definitions = $input->getArgument('cnd-file'); - if (count($definitions) == 0) { - throw new InvalidArgumentException('At least one definition (i.e. file or folder) must be specified'); + if (0 == count($definitions)) { + throw new \InvalidArgumentException('At least one definition (i.e. file or folder) must be specified'); } $allowUpdate = $input->getOption('allow-update'); @@ -79,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $cnd = file_get_contents($filePath); $this->updateFromCnd($output, $session, $cnd, $allowUpdate); $output->writeln(sprintf('Node type definition: %s', $filePath)); - $count++; + ++$count; } $output->writeln(sprintf('%d node definition(s) registered', $count)); @@ -93,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int * @param OutputInterface $output the console output stream * @param SessionInterface $session the PHPCR session to talk to * @param string $cnd the compact namespace and node type definition in string form - * @param bool $allowUpdate whether to allow updating existing node types. + * @param bool $allowUpdate whether to allow updating existing node types * * @throws RepositoryException on other errors */ @@ -120,9 +119,9 @@ protected function updateFromCnd(OutputInterface $output, SessionInterface $sess * * @param array $definitions List of files of folders * - * @throws InvalidArgumentException + * @return array array of full paths to all the type node definition files * - * @return array Array of full paths to all the type node definition files. + * @throws \InvalidArgumentException */ protected function getFilePaths($definitions) { @@ -140,7 +139,7 @@ protected function getFilePaths($definitions) $filePath = sprintf('%s/%s', $definition, $file); if (!is_readable($filePath)) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( sprintf("Node type definition file '%s' does not have read permissions.", $file) ); } @@ -149,7 +148,7 @@ protected function getFilePaths($definitions) } } else { if (!file_exists($definition)) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( sprintf("Node type definition file / folder '%s' does not exist.", $definition) ); } @@ -163,6 +162,6 @@ protected function getFilePaths($definitions) protected function fileIsNodeType($filename) { - return substr($filename, -4) === '.cnd'; + return '.cnd' === substr($filename, -4); } } diff --git a/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php b/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php index 6e29b1dd..dd8ca70c 100644 --- a/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php +++ b/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Command; -use InvalidArgumentException; use PHPCR\Query\QueryResultInterface; use PHPCR\Query\RowInterface; use Symfony\Component\Console\Exception\InvalidArgumentException as CliInvalidArgumentException; @@ -81,7 +80,7 @@ protected function configure(): void /** * @throws CliInvalidArgumentException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output): int { @@ -98,13 +97,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $session = $this->getPhpcrSession(); if (!$query) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( 'You must provide a SELECT query, e.g. --query="SELECT * FROM [nt:unstructured]"' ); } - if (strtoupper(substr($query, 0, 6)) !== 'SELECT') { - throw new InvalidArgumentException("Query doesn't look like a SELECT query: '$query'"); + if ('SELECT' !== strtoupper(substr($query, 0, 6))) { + throw new \InvalidArgumentException("Query doesn't look like a SELECT query: '$query'"); } $query = $helper->createQuery($queryLanguage, $query); @@ -129,14 +128,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $node = $row->getNode(); $helper->processNode($output, $node, [ - 'setProp' => $setProp, - 'removeProp' => $removeProp, - 'addMixins' => $addMixins, - 'removeMixins' => $removeMixins, + 'setProp' => $setProp, + 'removeProp' => $removeProp, + 'addMixins' => $addMixins, + 'removeMixins' => $removeMixins, 'applyClosures' => $applyClosures, ]); - $persistIn--; + --$persistIn; if (0 === $persistIn) { $output->writeln('Saving nodes processed so far...'); $session->save(); @@ -152,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** - * @return bool Whether to execute the action or not. + * @return bool whether to execute the action or not */ private function shouldExecute(InputInterface $input, OutputInterface $output, QueryResultInterface $result) { @@ -161,7 +160,7 @@ private function shouldExecute(InputInterface $input, OutputInterface $output, Q count($result->getRows()) ))); - if ($response === 'L') { + if ('L' === $response) { /** @var RowInterface $row */ foreach ($result as $i => $row) { $output->writeln(sprintf(' - [%d] %s', $i, $row->getPath())); @@ -170,11 +169,11 @@ private function shouldExecute(InputInterface $input, OutputInterface $output, Q return $this->shouldExecute($input, $output, $result); } - if ($response === 'N') { + if ('N' === $response) { return false; } - if ($response === 'Y') { + if ('Y' === $response) { return true; } diff --git a/src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php index c8e0f7b3..1487b4af 100644 --- a/src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceExportCommand.php @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 2; } - $session->exportSystemView($path, $stream, $input->getOption('skip_binary') === 'yes', $input->getOption('recurse') === 'no'); + $session->exportSystemView($path, $stream, 'yes' === $input->getOption('skip_binary'), 'no' === $input->getOption('recurse')); $output->writeln(sprintf( 'Successfully exported workspace "%s", path "%s" to file "%s".', diff --git a/src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php index 1641d7f5..109f3f96 100644 --- a/src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceImportCommand.php @@ -17,11 +17,11 @@ */ class WorkspaceImportCommand extends BaseCommand { - const UUID_BEHAVIOR = [ - 'new' => ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW, - 'remove' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REMOVE_EXISTING, + public const UUID_BEHAVIOR = [ + 'new' => ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW, + 'remove' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REMOVE_EXISTING, 'replace' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REPLACE_EXISTING, - 'throw' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW, + 'throw' => ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW, ]; protected function configure(): void diff --git a/src/PHPCR/Util/Console/Helper/PhpcrConsoleDumperHelper.php b/src/PHPCR/Util/Console/Helper/PhpcrConsoleDumperHelper.php index 04c35226..f22c51b5 100644 --- a/src/PHPCR/Util/Console/Helper/PhpcrConsoleDumperHelper.php +++ b/src/PHPCR/Util/Console/Helper/PhpcrConsoleDumperHelper.php @@ -20,9 +20,9 @@ class PhpcrConsoleDumperHelper extends Helper public function getTreeWalker(OutputInterface $output, $options) { $options = array_merge([ - 'dump_uuids' => false, - 'ref_format' => 'uuid', - 'show_props' => false, + 'dump_uuids' => false, + 'ref_format' => 'uuid', + 'show_props' => false, 'show_sys_nodes' => false, ], $options); diff --git a/src/PHPCR/Util/Console/Helper/PhpcrHelper.php b/src/PHPCR/Util/Console/Helper/PhpcrHelper.php index 8e044dd5..68608c98 100644 --- a/src/PHPCR/Util/Console/Helper/PhpcrHelper.php +++ b/src/PHPCR/Util/Console/Helper/PhpcrHelper.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Helper; -use Exception; use PHPCR\NodeInterface; use PHPCR\PropertyInterface; use PHPCR\SessionInterface; @@ -54,19 +53,19 @@ public function getName(): string * * Provides common processing for both touch and update commands. * - * @param OutputInterface $output used for status updates. - * @param NodeInterface $node the node to manipulate. - * @param array $operations to execute on that node. + * @param OutputInterface $output used for status updates + * @param NodeInterface $node the node to manipulate + * @param array $operations to execute on that node */ public function processNode(OutputInterface $output, NodeInterface $node, array $operations) { $operations = array_merge([ - 'setProp' => [], - 'removeProp' => [], - 'addMixins' => [], - 'removeMixins' => [], + 'setProp' => [], + 'removeProp' => [], + 'addMixins' => [], + 'removeMixins' => [], 'applyClosures' => [], - 'dump' => false, + 'dump' => false, ], $operations); foreach ($operations['setProp'] as $set) { @@ -164,9 +163,9 @@ public function createQuery($language, $sql) /** * Check if this is a supported query language. * - * @param string $language Language name. + * @param string $language language name * - * @throws \Exception if the language is not supported. + * @throws \Exception if the language is not supported */ protected function validateQueryLanguage($language) { @@ -178,7 +177,7 @@ protected function validateQueryLanguage($language) } } - throw new Exception(sprintf( + throw new \Exception(sprintf( 'Query language "%s" not supported, available query languages: %s', $language, implode(',', $langs) diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php index ddd16233..fe334e17 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php @@ -28,8 +28,6 @@ abstract class ConsoleDumperItemVisitor implements ItemVisitorInterface /** * Instantiate the console dumper visitor. - * - * @param OutputInterface $output */ public function __construct(OutputInterface $output) { diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php index c64438b3..3656b18e 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Helper\TreeDumper; -use Exception; use PHPCR\ItemInterface; use PHPCR\NodeInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -29,8 +28,7 @@ class ConsoleDumperNodeVisitor extends ConsoleDumperItemVisitor /** * Instantiate the console dumper visitor. * - * @param OutputInterface $output - * @param bool $identifiers whether to output the node UUID + * @param bool $identifiers whether to output the node UUID */ public function __construct(OutputInterface $output, $identifiers = false) { @@ -53,15 +51,15 @@ public function setShowFullPath($showFullPath) * * @param ItemInterface $item the node to visit * - * @throws Exception + * @throws \Exception */ public function visit(ItemInterface $item) { if (!$item instanceof NodeInterface) { - throw new Exception('Internal error: did not expect to visit a non-node object: '.get_class($item)); + throw new \Exception('Internal error: did not expect to visit a non-node object: '.get_class($item)); } - if ($item->getDepth() === 0) { + if (0 === $item->getDepth()) { $name = 'ROOT'; } elseif ($this->showFullPath) { $name = $item->getPath(); diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php index 63ccbc7b..6202b495 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\Console\Helper\TreeDumper; -use Exception; use PHPCR\ItemInterface; use PHPCR\PropertyInterface; use PHPCR\PropertyType; @@ -35,14 +34,13 @@ class ConsoleDumperPropertyVisitor extends ConsoleDumperItemVisitor /** * Instantiate property visitor. * - * @param OutputInterface $output - * @param array $options + * @param array $options */ public function __construct(OutputInterface $output, $options = []) { $options = array_merge([ 'max_line_length' => 120, - 'ref_format' => 'uuid', + 'ref_format' => 'uuid', ], $options); parent::__construct($output); @@ -56,12 +54,12 @@ public function __construct(OutputInterface $output, $options = []) * * @param ItemInterface $item the property to visit * - * @throws Exception + * @throws \Exception */ public function visit(ItemInterface $item) { if (!$item instanceof PropertyInterface) { - throw new Exception(sprintf('Internal error: did not expect to visit a non-property object: %s', is_object($item) ? get_class($item) : $item)); + throw new \Exception(sprintf('Internal error: did not expect to visit a non-property object: %s', is_object($item) ? get_class($item) : $item)); } $value = $item->getString(); diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/SystemNodeFilter.php b/src/PHPCR/Util/Console/Helper/TreeDumper/SystemNodeFilter.php index 51c1cf67..9c6e86c4 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/SystemNodeFilter.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/SystemNodeFilter.php @@ -17,11 +17,9 @@ class SystemNodeFilter implements TreeWalkerFilterInterface /** * Checks whether this item is a system item. * - * @param ItemInterface $item + * @return bool * * @throws RepositoryException - * - * @return bool */ public function mustVisit(ItemInterface $item) { diff --git a/src/PHPCR/Util/NodeHelper.php b/src/PHPCR/Util/NodeHelper.php index fada226e..84e80900 100644 --- a/src/PHPCR/Util/NodeHelper.php +++ b/src/PHPCR/Util/NodeHelper.php @@ -2,7 +2,6 @@ namespace PHPCR\Util; -use InvalidArgumentException; use PHPCR\ItemExistsException; use PHPCR\ItemInterface; use PHPCR\ItemNotFoundException; @@ -39,15 +38,15 @@ private function __construct() * @param SessionInterface $session the PHPCR session to create the path * @param string $path full path, like /content/jobs/data * - * @throws InvalidArgumentException + * @return NodeInterface the last node of the path, i.e. data + * + * @throws \InvalidArgumentException * @throws RepositoryException * @throws PathNotFoundException * @throws ItemExistsException * @throws LockException * @throws ConstraintViolationException * @throws VersionException - * - * @return NodeInterface the last node of the path, i.e. data */ public static function createPath(SessionInterface $session, $path) { @@ -104,8 +103,6 @@ public static function purgeWorkspace(SessionInterface $session) /** * Kept as alias of purgeWorkspace for BC compatibility. * - * @param SessionInterface $session - * * @throws RepositoryException * * @deprecated @@ -120,11 +117,9 @@ public static function deleteAllNodes(SessionInterface $session) * usually want to hide and that should not be removed when purging the * repository. * - * @param ItemInterface $item + * @return bool true if $item is a system item, false otherwise * * @throws RepositoryException - * - * @return bool true if $item is a system item, false otherwise */ public static function isSystemItem(ItemInterface $item) { @@ -133,7 +128,7 @@ public static function isSystemItem(ItemInterface $item) } $name = $item->getName(); - return strpos($name, 'jcr:') === 0 || strpos($name, 'rep:') === 0; + return 0 === strpos($name, 'jcr:') || 0 === strpos($name, 'rep:'); } /** @@ -142,17 +137,17 @@ public static function isSystemItem(ItemInterface $item) * This method only checks for valid namespaces. All other exceptions must * be thrown by the addNodeAutoNamed implementation. * - * @param string[] $usedNames list of child names that is currently used and may not be chosen. - * @param string[] $namespaces namespace prefix to uri map of all currently known namespaces. - * @param string $defaultNamespace namespace prefix to use if the hint does not specify. + * @param string[] $usedNames list of child names that is currently used and may not be chosen + * @param string[] $namespaces namespace prefix to uri map of all currently known namespaces + * @param string $defaultNamespace namespace prefix to use if the hint does not specify * @param string $nameHint the name hint according to the API definition * + * @return string A valid node name for this node + * * @throws NamespaceException if a namespace prefix is provided in the * $nameHint which does not exist and this implementation performs - * this validation immediately. + * this validation immediately * @throws RepositoryException - * - * @return string A valid node name for this node */ public static function generateAutoNodeName($usedNames, $namespaces, $defaultNamespace, $nameHint = null) { @@ -179,7 +174,7 @@ public static function generateAutoNodeName($usedNames, $namespaces, $defaultNam * valid namespace prefix */ if (':' === $nameHint[strlen($nameHint) - 1] - && substr_count($nameHint, ':') === 1 + && 1 === substr_count($nameHint, ':') && preg_match('#^[a-zA-Z][a-zA-Z0-9]*:$#', $nameHint) ) { $prefix = substr($nameHint, 0, -1); @@ -288,13 +283,13 @@ private static function generateWithPrefix($usedNames, $prefix, $namepart = '') * @param array $new new order * * @return array the keys are elements to move, values the destination to - * move before or null to move to the end. + * move before or null to move to the end */ public static function calculateOrderBefore(array $old, array $new) { $reorders = []; - //check for deleted items + // check for deleted items $newIndex = array_flip($new); foreach ($old as $key => $value) { @@ -310,22 +305,22 @@ public static function calculateOrderBefore(array $old, array $new) $len = count($new) - 1; $oldIndex = array_flip($old); - //go backwards on the new node order and arrange them this way - for ($i = $len; $i >= 0; $i--) { - //get the name of the child node + // go backwards on the new node order and arrange them this way + for ($i = $len; $i >= 0; --$i) { + // get the name of the child node $current = $new[$i]; - //check if it's not the last node + // check if it's not the last node if (isset($new[$i + 1])) { // get the name of the next node $next = $new[$i + 1]; - //if in the old order $c and next are not neighbors already, do the reorder command + // if in the old order $c and next are not neighbors already, do the reorder command if ($oldIndex[$current] + 1 != $oldIndex[$next]) { $reorders[$current] = $next; $old = self::orderBeforeArray($current, $next, $old); $oldIndex = array_flip($old); } } else { - //check if it's not already at the end of the nodes + // check if it's not already at the end of the nodes if ($oldIndex[$current] != $len) { $reorders[$current] = null; $old = self::orderBeforeArray($current, null, $old); @@ -346,9 +341,9 @@ public static function calculateOrderBefore(array $old, array $new) * to be ordered before, null to move to the end * @param array $list the array of names * - * @throws ItemNotFoundException if $srcChildRelPath or $destChildRelPath are not found in $nodes - * * @return array The updated $nodes array with new order + * + * @throws ItemNotFoundException if $srcChildRelPath or $destChildRelPath are not found in $nodes */ public static function orderBeforeArray($name, $destination, $list) { @@ -360,19 +355,19 @@ public static function orderBeforeArray($name, $destination, $list) throw new ItemNotFoundException("$name is not a child of this node"); } - if ($destination == null) { + if (null == $destination) { // null means move to end unset($list[$oldpos]); $list[] = $name; } else { // insert before element $destination $newpos = array_search($destination, $list); - if ($newpos === false) { + if (false === $newpos) { throw new ItemNotFoundException("$destination is not a child of this node"); } if ($oldpos < $newpos) { // we first unset, the position will change by one - $newpos--; + --$newpos; } unset($list[$oldpos]); array_splice($list, $newpos, 0, $name); diff --git a/src/PHPCR/Util/PathHelper.php b/src/PHPCR/Util/PathHelper.php index 8fba4160..649ef73d 100644 --- a/src/PHPCR/Util/PathHelper.php +++ b/src/PHPCR/Util/PathHelper.php @@ -40,14 +40,14 @@ private function __construct() * @param array|bool $namespacePrefixes List of all known namespace prefixes. * If specified, this method validates that the path contains no unknown prefixes. * - * @throws RepositoryException if the path contains invalid characters and $throw is true - * * @return bool true if valid, false if not valid and $throw was false + * + * @throws RepositoryException if the path contains invalid characters and $throw is true */ public static function assertValidAbsolutePath($path, $destination = false, $throw = true, $namespacePrefixes = false) { if ((!is_string($path) && !is_numeric($path)) - || strlen($path) === 0 + || 0 === strlen($path) || '/' !== $path[0] || strlen($path) > 1 && '/' === $path[strlen($path) - 1] || preg_match('-//|/\./|/\.\./-', $path) @@ -85,12 +85,12 @@ public static function assertValidAbsolutePath($path, $destination = false, $thr * engine. * * @param string $name The name to check - * @param bool $throw whether to throw an exception on validation errors. - * - * @throws RepositoryException if the name is invalid and $throw is true + * @param bool $throw whether to throw an exception on validation errors * * @return bool true if valid, false if not valid and $throw was false * + * @throws RepositoryException if the name is invalid and $throw is true + * * @see http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.2.2%20Local%20Names */ public static function assertValidLocalName($name, $throw = true) @@ -117,23 +117,23 @@ public static function assertValidLocalName($name, $throw = true) * * Note: A well-formed input path implies a well-formed and normalized path returned. * - * @param string $path The path to normalize. + * @param string $path the path to normalize * @param bool $destination whether this is a destination path (by copy or - * move), meaning [] is not allowed in validation. + * move), meaning [] is not allowed in validation * @param bool $throw whether to throw an exception if validation fails or - * just to return false. + * just to return false + * + * @return string The normalized path or false if $throw was false and the path invalid * * @throws RepositoryException if the path is not a valid absolute path and * $throw is true - * - * @return string The normalized path or false if $throw was false and the path invalid */ public static function normalizePath($path, $destination = false, $throw = true) { if (!is_string($path) && !is_numeric($path)) { return self::error('Expected string but got '.gettype($path), $throw); } - if (strlen($path) === 0) { + if (0 === strlen($path)) { return self::error('Path must not be of zero length', $throw); } @@ -181,15 +181,15 @@ public static function normalizePath($path, $destination = false, $throw = true) * @param string $path A relative or absolute path * @param string $context The absolute path context to make $path absolute if needed * @param bool $destination whether this is a destination path (by copy or - * move), meaning [] is not allowed in validation. + * move), meaning [] is not allowed in validation * @param bool $throw whether to throw an exception if validation fails or - * just to return false. - * - * @throws RepositoryException if the path can not be made into a valid - * absolute path and $throw is true + * just to return false * * @return string The normalized, absolute path or false if $throw was * false and the path invalid + * + * @throws RepositoryException if the path can not be made into a valid + * absolute path and $throw is true */ public static function absolutizePath($path, $context, $destination = false, $throw = true) { @@ -199,7 +199,7 @@ public static function absolutizePath($path, $context, $destination = false, $th if (!is_string($context)) { return self::error('Expected string context but got '.gettype($context), $throw); } - if (strlen($path) === 0) { + if (0 === strlen($path)) { return self::error('Path must not be of zero length', $throw); } @@ -219,7 +219,7 @@ public static function absolutizePath($path, $context, $destination = false, $th * * @param string $path The absolute path to a node * @param string $context The absolute path to an ancestor of $path - * @param bool $throw Whether to throw exceptions on invalid data. + * @param bool $throw whether to throw exceptions on invalid data * * @return string The relative path from $context to $path */ @@ -261,9 +261,9 @@ public static function getParentPath($path) * * @param string $path a valid absolute path, like /content/jobs/data * - * @throws RepositoryException - * * @return string the name, that is the string after the last "/" + * + * @throws RepositoryException */ public static function getNodeName($path) { @@ -285,9 +285,9 @@ public static function getNodeName($path) * * @param string $path a valid absolute path * - * @throws RepositoryException - * * @return string The localname + * + * @throws RepositoryException */ public static function getLocalNodeName($path) { @@ -320,9 +320,9 @@ public static function getPathDepth($path) * @param string $msg the exception message to use in case of throw being true * @param bool $throw whether to throw the exception or return false * - * @throws RepositoryException - * * @return bool false + * + * @throws RepositoryException */ private static function error($msg, $throw) { diff --git a/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php b/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php index b9f2801e..b74f1af4 100644 --- a/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php +++ b/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\QOM; -use InvalidArgumentException; use PHPCR\Query\QOM; use PHPCR\Query\QOM\StaticOperandInterface; @@ -23,8 +22,6 @@ abstract class BaseQomToSqlQueryConverter /** * Instantiate the converter. - * - * @param BaseSqlGenerator $generator */ public function __construct(BaseSqlGenerator $generator) { @@ -37,8 +34,6 @@ public function __construct(BaseSqlGenerator $generator) * ['WHERE' Constraint] * ['ORDER BY' orderings]. * - * @param QOM\QueryObjectModelInterface $query - * * @return string */ public function convert(QOM\QueryObjectModelInterface $query) @@ -48,7 +43,7 @@ public function convert(QOM\QueryObjectModelInterface $query) $constraint = ''; $orderings = ''; - if ($query->getConstraint() !== null) { + if (null !== $query->getConstraint()) { $constraint = $this->convertConstraint($query->getConstraint()); } @@ -62,8 +57,6 @@ public function convert(QOM\QueryObjectModelInterface $query) /** * Convert a source. This is different between SQL1 and SQL2. * - * @param QOM\SourceInterface $source - * * @return string */ abstract protected function convertSource(QOM\SourceInterface $source); @@ -71,18 +64,12 @@ abstract protected function convertSource(QOM\SourceInterface $source); /** * Convert a constraint. This is different between SQL1 and SQL2. * - * @param QOM\ConstraintInterface $constraint - * * @return string */ abstract protected function convertConstraint(QOM\ConstraintInterface $constraint); /** * Convert dynamic operand. This is different between SQL1 and SQL2. - * - * @param QOM\DynamicOperandInterface $operand - * - * @return mixed */ abstract protected function convertDynamicOperand(QOM\DynamicOperandInterface $operand); @@ -90,8 +77,6 @@ abstract protected function convertDynamicOperand(QOM\DynamicOperandInterface $o * Selector ::= nodeTypeName ['AS' selectorName] * nodeTypeName ::= Name. * - * @param QOM\SelectorInterface $selector - * * @return string */ protected function convertSelector(QOM\SelectorInterface $selector) @@ -113,8 +98,6 @@ protected function convertSelector(QOM\SelectorInterface $selector) * GreaterThanOrEqualTo ::= '>=' * Like ::= 'LIKE' * - * @param QOM\ComparisonInterface $comparison - * * @return string */ protected function convertComparison(QOM\ComparisonInterface $comparison) @@ -136,8 +119,6 @@ protected function convertComparison(QOM\ComparisonInterface $comparison) * Note: The negation, 'NOT x IS NOT NULL' * can be written 'x IS NULL' * - * @param QOM\PropertyExistenceInterface $constraint - * * @return string */ protected function convertPropertyExistence(QOM\PropertyExistenceInterface $constraint) @@ -157,8 +138,6 @@ protected function convertPropertyExistence(QOM\PropertyExistenceInterface $cons * explicit specification of the selectorName * preceding the propertyName is optional. * - * @param QOM\FullTextSearchInterface $constraint - * * @return string */ protected function convertFullTextSearch(QOM\FullTextSearchInterface $constraint) @@ -187,7 +166,7 @@ protected function convertFullTextSearchExpression($expr) // however, without type checks, jackalope 1.0 got this wrong and returned a string. $literal = $expr; } else { - throw new InvalidArgumentException('Unknown full text search expression type '.get_class($expr)); + throw new \InvalidArgumentException('Unknown full text search expression type '.get_class($expr)); } $literal = $this->generator->evalFullText($literal); @@ -210,11 +189,9 @@ protected function convertFullTextSearchExpression($expr) * BindVariableValue ::= '$'bindVariableName * bindVariableName ::= Prefix * - * @param QOM\StaticOperandInterface $operand - * - * @throws InvalidArgumentException - * * @return string + * + * @throws \InvalidArgumentException */ protected function convertStaticOperand(QOM\StaticOperandInterface $operand) { @@ -226,14 +203,12 @@ protected function convertStaticOperand(QOM\StaticOperandInterface $operand) } // This should not happen, but who knows... - throw new InvalidArgumentException('Invalid operand'); + throw new \InvalidArgumentException('Invalid operand'); } /** * PropertyValue ::= [selectorName'.'] propertyName // If only one selector exists. * - * @param QOM\PropertyValueInterface $value - * * @return string */ protected function convertPropertyValue(QOM\PropertyValueInterface $value) @@ -297,8 +272,6 @@ protected function convertBindVariable($var) /** * Literal ::= CastLiteral | UncastLiteral. * - * @param mixed $literal - * * @return string */ protected function convertLiteral($literal) diff --git a/src/PHPCR/Util/QOM/BaseSqlGenerator.php b/src/PHPCR/Util/QOM/BaseSqlGenerator.php index e023fbdc..5226cd4d 100644 --- a/src/PHPCR/Util/QOM/BaseSqlGenerator.php +++ b/src/PHPCR/Util/QOM/BaseSqlGenerator.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\QOM; -use DateTime; use PHPCR\PropertyType; use PHPCR\Query\QOM\QueryObjectModelConstantsInterface as Constants; use PHPCR\Util\ValueConverter; @@ -163,8 +162,6 @@ public function evalUpper($operand) /** * orderings ::= Ordering {',' Ordering}. * - * @param $orderings - * * @return string */ public function evalOrderings($orderings) @@ -172,7 +169,7 @@ public function evalOrderings($orderings) $sql = ''; foreach ($orderings as $ordering) { - if ($sql !== '') { + if ('' !== $sql) { $sql .= ', '; } @@ -185,9 +182,6 @@ public function evalOrderings($orderings) /** * Ordering ::= DynamicOperand [Order]. * - * @param $operand - * @param $order - * * @return string */ public function evalOrdering($operand, $order) @@ -200,8 +194,6 @@ public function evalOrdering($operand, $order) * Ascending ::= 'ASC' * Descending ::= 'DESC'. * - * @param $order - * * @return string */ public function evalOrder($order) @@ -220,8 +212,6 @@ public function evalOrder($order) * BindVariableValue ::= '$'bindVariableName * bindVariableName ::= Prefix. * - * @param $var - * * @return string */ public function evalBindVariable($var) @@ -241,8 +231,8 @@ public function evalBindVariable($var) public function evalFullText($string) { $illegalCharacters = [ - '!' => '\\!', '(' => '\\(', ':' => '\\:', '^' => '\\^', - '[' => '\\[', ']' => '\\]', '{' => '\\{', '}' => '\\}', + '!' => '\\!', '(' => '\\(', ':' => '\\:', '^' => '\\^', + '[' => '\\[', ']' => '\\]', '{' => '\\{', '}' => '\\}', '\"' => '\\\"', '?' => '\\?', "'" => "''", ]; @@ -252,13 +242,11 @@ public function evalFullText($string) /** * Literal ::= CastLiteral | UncastLiteral. * - * @param mixed $literal - * * @return string */ public function evalLiteral($literal) { - if ($literal instanceof DateTime) { + if ($literal instanceof \DateTime) { $string = $this->valueConverter->convertType($literal, PropertyType::STRING); return $this->evalCastLiteral($string, 'DATE'); @@ -316,8 +304,6 @@ abstract public function evalPath($path); * * With empty columns, SQL1 is different from SQL2 * - * @param $columns - * * @return string */ abstract public function evalColumns($columns); @@ -332,9 +318,6 @@ abstract public function evalColumns($columns); abstract public function evalColumn($selectorName, $propertyName = null, $colname = null); /** - * @param $selectorName - * @param $propertyName - * * @return string */ abstract public function evalPropertyExistence($selectorName, $propertyName); diff --git a/src/PHPCR/Util/QOM/NotSupportedConstraintException.php b/src/PHPCR/Util/QOM/NotSupportedConstraintException.php index 223e8507..39a543d0 100644 --- a/src/PHPCR/Util/QOM/NotSupportedConstraintException.php +++ b/src/PHPCR/Util/QOM/NotSupportedConstraintException.php @@ -2,15 +2,13 @@ namespace PHPCR\Util\QOM; -use RuntimeException; - /** * A helper exception to report not yet implemented functionality. * * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004 * @license http://opensource.org/licenses/MIT MIT License */ -class NotSupportedConstraintException extends RuntimeException +class NotSupportedConstraintException extends \RuntimeException { /** * Create the exception with an explaining message. diff --git a/src/PHPCR/Util/QOM/NotSupportedOperandException.php b/src/PHPCR/Util/QOM/NotSupportedOperandException.php index bc7f317e..af6457ea 100644 --- a/src/PHPCR/Util/QOM/NotSupportedOperandException.php +++ b/src/PHPCR/Util/QOM/NotSupportedOperandException.php @@ -2,15 +2,13 @@ namespace PHPCR\Util\QOM; -use RuntimeException; - /** * A helper exception to report not yet implemented functionality. * * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004 * @license http://opensource.org/licenses/MIT MIT License */ -class NotSupportedOperandException extends RuntimeException +class NotSupportedOperandException extends \RuntimeException { /** * Create the exception with an explaining message. diff --git a/src/PHPCR/Util/QOM/QomToSql1QueryConverter.php b/src/PHPCR/Util/QOM/QomToSql1QueryConverter.php index ae591b59..4c75be44 100644 --- a/src/PHPCR/Util/QOM/QomToSql1QueryConverter.php +++ b/src/PHPCR/Util/QOM/QomToSql1QueryConverter.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\QOM; -use InvalidArgumentException; use PHPCR\Query\QOM; /** @@ -16,11 +15,9 @@ class QomToSql1QueryConverter extends BaseQomToSqlQueryConverter /** * Source ::= Selector. * - * @param QOM\SourceInterface $source - * - * @throws InvalidArgumentException - * * @return string + * + * @throws \InvalidArgumentException */ protected function convertSource(QOM\SourceInterface $source) { @@ -28,7 +25,7 @@ protected function convertSource(QOM\SourceInterface $source) return $this->convertSelector($source); } - throw new InvalidArgumentException('Invalid Source'); + throw new \InvalidArgumentException('Invalid Source'); } /** @@ -40,12 +37,10 @@ protected function convertSource(QOM\SourceInterface $source) * Or ::= constraint1 'OR' constraint2 * Not ::= 'NOT' Constraint * - * @param QOM\ConstraintInterface $constraint + * @return string * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws NotSupportedConstraintException - * - * @return string */ protected function convertConstraint(QOM\ConstraintInterface $constraint) { @@ -96,7 +91,7 @@ protected function convertConstraint(QOM\ConstraintInterface $constraint) // This should not happen, but who knows... $class = get_class($constraint); - throw new InvalidArgumentException("Invalid operand: $class"); + throw new \InvalidArgumentException("Invalid operand: $class"); } /** @@ -105,12 +100,10 @@ protected function convertConstraint(QOM\ConstraintInterface $constraint) * LowerCase ::= 'LOWER(' DynamicOperand ')' * UpperCase ::= 'UPPER(' DynamicOperand ')' * - * @param QOM\DynamicOperandInterface $operand + * @return string * * @throws NotSupportedOperandException - * @throws InvalidArgumentException - * - * @return string + * @throws \InvalidArgumentException */ protected function convertDynamicOperand(QOM\DynamicOperandInterface $operand) { @@ -147,6 +140,6 @@ protected function convertDynamicOperand(QOM\DynamicOperandInterface $operand) } // This should not happen, but who knows... - throw new InvalidArgumentException('Invalid operand'); + throw new \InvalidArgumentException('Invalid operand'); } } diff --git a/src/PHPCR/Util/QOM/QomToSql2QueryConverter.php b/src/PHPCR/Util/QOM/QomToSql2QueryConverter.php index fdef9c07..b5dd984c 100644 --- a/src/PHPCR/Util/QOM/QomToSql2QueryConverter.php +++ b/src/PHPCR/Util/QOM/QomToSql2QueryConverter.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\QOM; -use InvalidArgumentException; use PHPCR\Query\QOM; /** @@ -16,11 +15,9 @@ class QomToSql2QueryConverter extends BaseQomToSqlQueryConverter /** * Source ::= Selector | Join. * - * @param QOM\SourceInterface $source - * - * @throws InvalidArgumentException - * * @return string + * + * @throws \InvalidArgumentException */ protected function convertSource(QOM\SourceInterface $source) { @@ -31,7 +28,7 @@ protected function convertSource(QOM\SourceInterface $source) return $this->convertJoin($source); } - throw new InvalidArgumentException('Invalid Source'); + throw new \InvalidArgumentException('Invalid Source'); } /** @@ -45,8 +42,6 @@ protected function convertSource(QOM\SourceInterface $source) * LeftOuter ::= 'LEFT OUTER' * RightOuter ::= 'RIGHT OUTER' * - * @param QOM\JoinInterface $join - * * @return string */ protected function convertJoin(QOM\JoinInterface $join) @@ -68,11 +63,9 @@ protected function convertJoin(QOM\JoinInterface $join) * ChildNodeJoinCondition | * DescendantNodeJoinCondition. * - * @param QOM\JoinConditionInterface $condition - * - * @throws InvalidArgumentException - * * @return string + * + * @throws \InvalidArgumentException */ protected function convertJoinCondition(QOM\JoinConditionInterface $condition) { @@ -90,7 +83,7 @@ protected function convertJoinCondition(QOM\JoinConditionInterface $condition) } // This should not happen, but who knows... - throw new InvalidArgumentException('Invalid operand'); + throw new \InvalidArgumentException('Invalid operand'); } /** @@ -101,8 +94,6 @@ protected function convertJoinCondition(QOM\JoinConditionInterface $condition) * property1Name ::= propertyName * property2Name ::= propertyName. * - * @param QOM\EquiJoinConditionInterface $condition - * * @return string */ protected function convertEquiJoinCondition(QOM\EquiJoinConditionInterface $condition) @@ -126,8 +117,6 @@ protected function convertEquiJoinCondition(QOM\EquiJoinConditionInterface $cond * [',' selector2Path] ')' * selector2Path ::= Path. * - * @param QOM\SameNodeJoinConditionInterface $condition - * * @return string */ protected function convertSameNodeJoinCondition(QOM\SameNodeJoinConditionInterface $condition) @@ -150,8 +139,6 @@ protected function convertSameNodeJoinCondition(QOM\SameNodeJoinConditionInterfa * childSelectorName ::= selectorName * parentSelectorName ::= selectorName. * - * @param QOM\ChildNodeJoinConditionInterface $condition - * * @return string */ protected function convertChildNodeJoinCondition(QOM\ChildNodeJoinConditionInterface $condition) @@ -173,8 +160,6 @@ protected function convertChildNodeJoinCondition(QOM\ChildNodeJoinConditionInter * descendantSelectorName ::= selectorName * ancestorSelectorName ::= selectorName. * - * @param QOM\DescendantNodeJoinConditionInterface $condition - * * @return string */ protected function convertDescendantNodeJoinCondition(QOM\DescendantNodeJoinConditionInterface $condition) @@ -210,11 +195,9 @@ protected function convertDescendantNodeJoinCondition(QOM\DescendantNodeJoinCond * // If only one selector exists in this query, explicit * specification of the selectorName is optional * - * @param QOM\ConstraintInterface $constraint - * - * @throws InvalidArgumentException - * * @return string + * + * @throws \InvalidArgumentException */ protected function convertConstraint(QOM\ConstraintInterface $constraint) { @@ -273,7 +256,7 @@ protected function convertConstraint(QOM\ConstraintInterface $constraint) } // This should not happen, but who knows... - throw new InvalidArgumentException('Invalid operand: '.get_class($constraint)); + throw new \InvalidArgumentException('Invalid operand: '.get_class($constraint)); } /** @@ -288,11 +271,9 @@ protected function convertConstraint(QOM\ConstraintInterface $constraint) * LowerCase ::= 'LOWER(' DynamicOperand ')' * UpperCase ::= 'UPPER(' DynamicOperand ')' * - * @param QOM\DynamicOperandInterface $operand - * - * @throws InvalidArgumentException - * * @return string + * + * @throws \InvalidArgumentException */ protected function convertDynamicOperand(QOM\DynamicOperandInterface $operand) { @@ -345,6 +326,6 @@ protected function convertDynamicOperand(QOM\DynamicOperandInterface $operand) } // This should not happen, but who knows... - throw new InvalidArgumentException('Invalid operand'); + throw new \InvalidArgumentException('Invalid operand'); } } diff --git a/src/PHPCR/Util/QOM/QueryBuilder.php b/src/PHPCR/Util/QOM/QueryBuilder.php index 23c6c125..eb6211b8 100644 --- a/src/PHPCR/Util/QOM/QueryBuilder.php +++ b/src/PHPCR/Util/QOM/QueryBuilder.php @@ -2,7 +2,6 @@ namespace PHPCR\Util\QOM; -use InvalidArgumentException; use PHPCR\Query\QOM\ColumnInterface; use PHPCR\Query\QOM\ConstraintInterface; use PHPCR\Query\QOM\DynamicOperandInterface; @@ -14,7 +13,6 @@ use PHPCR\Query\QOM\SourceInterface; use PHPCR\Query\QueryInterface; use PHPCR\Query\QueryResultInterface; -use RuntimeException; /** * QueryBuilder class is responsible for dynamically create QOM queries. @@ -28,8 +26,8 @@ class QueryBuilder { /** The builder states. */ - const STATE_DIRTY = 0; - const STATE_CLEAN = 1; + public const STATE_DIRTY = 0; + public const STATE_CLEAN = 1; /** * @var int The state of the query object. Can be dirty or clean. @@ -42,14 +40,14 @@ class QueryBuilder private $qomFactory; /** - * @var int The maximum number of results to retrieve. + * @var int the maximum number of results to retrieve */ - private $firstResult = null; + private $firstResult; /** - * @var int The maximum number of results to retrieve. + * @var int the maximum number of results to retrieve */ - private $maxResults = null; + private $maxResults; /** * @var array with the orderings that determine the order of the result @@ -57,36 +55,34 @@ class QueryBuilder private $orderings = []; /** - * @var ConstraintInterface to apply to the query. + * @var ConstraintInterface to apply to the query */ - private $constraint = null; + private $constraint; /** - * @var array with the columns to be selected. + * @var array with the columns to be selected */ private $columns = []; /** - * @var SourceInterface source of the query. + * @var SourceInterface source of the query */ - private $source = null; + private $source; /** * QOM tree. * * @var QueryObjectModelInterface */ - private $query = null; + private $query; /** - * @var array The query parameters. + * @var array the query parameters */ private $params = []; /** * Initializes a new QueryBuilder. - * - * @param QueryObjectModelFactoryInterface $qomFactory */ public function __construct(QueryObjectModelFactoryInterface $qomFactory) { @@ -99,9 +95,9 @@ public function __construct(QueryObjectModelFactoryInterface $qomFactory) * @param string $statement the statement in the specified language * @param string $language the query language * - * @throws InvalidArgumentException + * @return QueryBuilder this QueryBuilder instance * - * @return QueryBuilder This QueryBuilder instance. + * @throws \InvalidArgumentException */ public function setFromQuery($statement, $language) { @@ -111,7 +107,7 @@ public function setFromQuery($statement, $language) } if (!$statement instanceof QueryObjectModelInterface) { - throw new InvalidArgumentException("Language '$language' not supported"); + throw new \InvalidArgumentException("Language '$language' not supported"); } $this->state = self::STATE_DIRTY; @@ -144,9 +140,9 @@ public function qomf() /** * sets the position of the first result to retrieve (the "offset"). * - * @param int $firstResult The First result to return. + * @param int $firstResult the First result to return * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function setFirstResult($firstResult) { @@ -159,7 +155,7 @@ public function setFirstResult($firstResult) * Gets the position of the first result the query object was set to retrieve (the "offset"). * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder. * - * @return int The position of the first result. + * @return int the position of the first result */ public function getFirstResult() { @@ -169,9 +165,9 @@ public function getFirstResult() /** * Sets the maximum number of results to retrieve (the "limit"). * - * @param int $maxResults The maximum number of results to retrieve. + * @param int $maxResults the maximum number of results to retrieve * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function setMaxResults($maxResults) { @@ -184,7 +180,7 @@ public function setMaxResults($maxResults) * Gets the maximum number of results the query object was set to retrieve (the "limit"). * Returns NULL if {@link setMaxResults} was not applied to this query builder. * - * @return int Maximum number of results. + * @return int maximum number of results */ public function getMaxResults() { @@ -194,7 +190,7 @@ public function getMaxResults() /** * Gets the array of orderings. * - * @return OrderingInterface[] Orderings to apply. + * @return OrderingInterface[] orderings to apply */ public function getOrderings() { @@ -204,23 +200,23 @@ public function getOrderings() /** * Adds an ordering to the query results. * - * @param DynamicOperandInterface $sort The ordering expression. - * @param string $order The ordering direction. + * @param DynamicOperandInterface $sort the ordering expression + * @param string $order the ordering direction * - * @throws InvalidArgumentException + * @return QueryBuilder this QueryBuilder instance * - * @return QueryBuilder This QueryBuilder instance. + * @throws \InvalidArgumentException */ public function addOrderBy(DynamicOperandInterface $sort, $order = 'ASC') { $order = strtoupper($order); if (!in_array($order, ['ASC', 'DESC'])) { - throw new InvalidArgumentException('Order must be one of "ASC" or "DESC"'); + throw new \InvalidArgumentException('Order must be one of "ASC" or "DESC"'); } $this->state = self::STATE_DIRTY; - if ($order === 'DESC') { + if ('DESC' === $order) { $ordering = $this->qomFactory->descending($sort); } else { $ordering = $this->qomFactory->ascending($sort); @@ -234,10 +230,10 @@ public function addOrderBy(DynamicOperandInterface $sort, $order = 'ASC') * Specifies an ordering for the query results. * Replaces any previously specified orderings, if any. * - * @param DynamicOperandInterface $sort The ordering expression. - * @param string $order The ordering direction. + * @param DynamicOperandInterface $sort the ordering expression + * @param string $order the ordering direction * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function orderBy(DynamicOperandInterface $sort, $order = 'ASC') { @@ -251,9 +247,7 @@ public function orderBy(DynamicOperandInterface $sort, $order = 'ASC') * Specifies one restriction (may be simple or composed). * Replaces any previously specified restrictions, if any. * - * @param ConstraintInterface $constraint - * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function where(ConstraintInterface $constraint) { @@ -286,9 +280,7 @@ public function getConstraint() * If there is no previous constraint then it will simply store the * provided one * - * @param ConstraintInterface $constraint - * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function andWhere(ConstraintInterface $constraint) { @@ -316,9 +308,7 @@ public function andWhere(ConstraintInterface $constraint) * If there is no previous constraint then it will simply store the * provided one * - * @param ConstraintInterface $constraint - * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function orWhere(ConstraintInterface $constraint) { @@ -348,7 +338,7 @@ public function getColumns() * * @param ColumnInterface[] $columns The columns to be selected * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function setColumns(array $columns) { @@ -365,7 +355,7 @@ public function setColumns(array $columns) * @param string $propertyName * @param string $columnName * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function select($selectorName, $propertyName, $columnName = null) { @@ -382,7 +372,7 @@ public function select($selectorName, $propertyName, $columnName = null) * @param string $propertyName * @param string $columnName * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function addSelect($selectorName, $propertyName, $columnName = null) { @@ -397,9 +387,7 @@ public function addSelect($selectorName, $propertyName, $columnName = null) * Sets the default Selector or the node-tuple Source. Can be a selector * or a join. * - * @param SourceInterface $source - * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function from(SourceInterface $source) { @@ -412,7 +400,7 @@ public function from(SourceInterface $source) /** * Gets the default Selector. * - * @return SourceInterface The default selector. + * @return SourceInterface the default selector */ public function getSource() { @@ -422,12 +410,9 @@ public function getSource() /** * Performs an inner join between the stored source and the supplied source. * - * @param SourceInterface $rightSource - * @param JoinConditionInterface $joinCondition + * @return QueryBuilder this QueryBuilder instance * - * @throws RuntimeException if there is not an existing source. - * - * @return QueryBuilder This QueryBuilder instance. + * @throws \RuntimeException if there is not an existing source */ public function join(SourceInterface $rightSource, JoinConditionInterface $joinCondition) { @@ -437,12 +422,9 @@ public function join(SourceInterface $rightSource, JoinConditionInterface $joinC /** * Performs an inner join between the stored source and the supplied source. * - * @param SourceInterface $rightSource - * @param JoinConditionInterface $joinCondition - * - * @throws RuntimeException if there is not an existing source. + * @return QueryBuilder this QueryBuilder instance * - * @return QueryBuilder This QueryBuilder instance. + * @throws \RuntimeException if there is not an existing source */ public function innerJoin(SourceInterface $rightSource, JoinConditionInterface $joinCondition) { @@ -452,12 +434,9 @@ public function innerJoin(SourceInterface $rightSource, JoinConditionInterface $ /** * Performs an left outer join between the stored source and the supplied source. * - * @param SourceInterface $rightSource - * @param JoinConditionInterface $joinCondition + * @return QueryBuilder this QueryBuilder instance * - * @throws RuntimeException if there is not an existing source. - * - * @return QueryBuilder This QueryBuilder instance. + * @throws \RuntimeException if there is not an existing source */ public function leftJoin(SourceInterface $rightSource, JoinConditionInterface $joinCondition) { @@ -467,12 +446,9 @@ public function leftJoin(SourceInterface $rightSource, JoinConditionInterface $j /** * Performs a right outer join between the stored source and the supplied source. * - * @param SourceInterface $rightSource - * @param JoinConditionInterface $joinCondition - * - * @throws RuntimeException if there is not an existing source. + * @return QueryBuilder this QueryBuilder instance * - * @return QueryBuilder This QueryBuilder instance. + * @throws \RuntimeException if there is not an existing source */ public function rightJoin(SourceInterface $rightSource, JoinConditionInterface $joinCondition) { @@ -482,18 +458,16 @@ public function rightJoin(SourceInterface $rightSource, JoinConditionInterface $ /** * Performs an join between the stored source and the supplied source. * - * @param SourceInterface $rightSource - * @param string $joinType as specified in PHPCR\Query\QOM\QueryObjectModelConstantsInterface - * @param JoinConditionInterface $joinCondition + * @param string $joinType as specified in PHPCR\Query\QOM\QueryObjectModelConstantsInterface * - * @throws RuntimeException if there is not an existing source. + * @return QueryBuilder this QueryBuilder instance * - * @return QueryBuilder This QueryBuilder instance. + * @throws \RuntimeException if there is not an existing source */ public function joinWithType(SourceInterface $rightSource, $joinType, JoinConditionInterface $joinCondition) { if (!$this->source) { - throw new RuntimeException('Cannot perform a join without a previous call to from'); + throw new \RuntimeException('Cannot perform a join without a previous call to from'); } $this->state = self::STATE_DIRTY; @@ -509,7 +483,7 @@ public function joinWithType(SourceInterface $rightSource, $joinType, JoinCondit */ public function getQuery() { - if ($this->query !== null && $this->state === self::STATE_CLEAN) { + if (null !== $this->query && self::STATE_CLEAN === $this->state) { return $this->query; } @@ -534,7 +508,7 @@ public function getQuery() */ public function execute() { - if ($this->query === null || $this->state === self::STATE_DIRTY) { + if (null === $this->query || self::STATE_DIRTY === $this->state) { $this->query = $this->getQuery(); } @@ -548,10 +522,10 @@ public function execute() /** * Sets a query parameter for the query being constructed. * - * @param string $key The parameter name. - * @param mixed $value The parameter value. + * @param string $key the parameter name + * @param mixed $value the parameter value * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function setParameter($key, $value) { @@ -563,9 +537,9 @@ public function setParameter($key, $value) /** * Gets a (previously set) query parameter of the query being constructed. * - * @param string $key The key (name) of the bound parameter. + * @param string $key the key (name) of the bound parameter * - * @return mixed The value of the bound parameter. + * @return mixed the value of the bound parameter */ public function getParameter($key) { @@ -575,9 +549,9 @@ public function getParameter($key) /** * Sets a collection of query parameters for the query being constructed. * - * @param array $params The query parameters to set. + * @param array $params the query parameters to set * - * @return QueryBuilder This QueryBuilder instance. + * @return QueryBuilder this QueryBuilder instance */ public function setParameters(array $params) { @@ -589,7 +563,7 @@ public function setParameters(array $params) /** * Gets all defined query parameters for the query being constructed. * - * @return array The currently defined query parameters. + * @return array the currently defined query parameters */ public function getParameters() { diff --git a/src/PHPCR/Util/QOM/Sql1Generator.php b/src/PHPCR/Util/QOM/Sql1Generator.php index 6c9927a2..bea5d88c 100644 --- a/src/PHPCR/Util/QOM/Sql1Generator.php +++ b/src/PHPCR/Util/QOM/Sql1Generator.php @@ -27,13 +27,11 @@ public function evalSelector($nodeTypeName, $selectorName = null) /** * Helper method to emulate descendant with LIKE query on path property. * - * @param $path - * * @return string */ protected function getPathForDescendantQuery($path) { - if ($path === '/') { + if ('/' === $path) { $sql1 = '/%'; } else { $path = trim($path, "\"'/"); @@ -81,7 +79,7 @@ public function evalDescendantNode($path, $selectorName = null) * propertyName 'IS NOT NULL'. * * @param string $selectorName declared to simplifiy interface - as there - * are no joins in SQL1 there is no need for a selector. + * are no joins in SQL1 there is no need for a selector * @param string $propertyName * * @return string @@ -117,21 +115,19 @@ public function evalFullTextSearch($selectorName, $searchExpression, $propertyNa /** * columns ::= (Column ',' {Column}) | '*'. * - * @param $columns - * * @return string */ public function evalColumns($columns) { if ((!is_array($columns) && !$columns instanceof \Countable) - || count($columns) === 0 + || 0 === count($columns) ) { return 's'; } $sql1 = ''; foreach ($columns as $column) { - if ($sql1 !== '') { + if ('' !== $sql1) { $sql1 .= ', '; } diff --git a/src/PHPCR/Util/QOM/Sql2Generator.php b/src/PHPCR/Util/QOM/Sql2Generator.php index 45fd7751..a819c6c5 100644 --- a/src/PHPCR/Util/QOM/Sql2Generator.php +++ b/src/PHPCR/Util/QOM/Sql2Generator.php @@ -220,9 +220,6 @@ public function evalDescendantNode($path, $selectorName = null) * selector exists in * this query. * - * @param $selectorName - * @param $propertyName - * * @return string */ public function evalPropertyExistence($selectorName, $propertyName) @@ -313,7 +310,7 @@ public function evalFullTextSearchScore($selectorValue = null) public function evalPropertyValue($propertyName, $selectorName = null) { $sql2 = null !== $selectorName ? $this->addBracketsIfNeeded($selectorName).'.' : ''; - if ('*' !== $propertyName && substr($propertyName, 0, 1) !== '[') { + if ('*' !== $propertyName && '[' !== substr($propertyName, 0, 1)) { $propertyName = "[$propertyName]"; } $sql2 .= $propertyName; @@ -324,21 +321,19 @@ public function evalPropertyValue($propertyName, $selectorName = null) /** * columns ::= (Column ',' {Column}) | '*'. * - * @param $columns - * * @return string */ public function evalColumns($columns) { if ((!is_array($columns) && !$columns instanceof \Countable) - || count($columns) === 0 + || 0 === count($columns) ) { return '*'; } $sql2 = ''; foreach ($columns as $column) { - if ($sql2 !== '') { + if ('' !== $sql2) { $sql2 .= ', '; } @@ -394,7 +389,7 @@ public function evalPath($path) } $sql2 = $path; // only ensure proper quoting if the user did not quote himself, we trust him to get it right if he did. - if (strpos($path, '[') !== 0 && substr($path, -1) !== ']') { + if (0 !== strpos($path, '[') && ']' !== substr($path, -1)) { if (false !== strpos($sql2, ' ') || false !== strpos($sql2, '.')) { $sql2 = '"'.$sql2.'"'; } @@ -423,8 +418,8 @@ public function evalCastLiteral($literal, $type) */ private function addBracketsIfNeeded($selector) { - if (substr($selector, 0, 1) !== '[' - && substr($selector, -1) !== ']' + if ('[' !== substr($selector, 0, 1) + && ']' !== substr($selector, -1) && false !== strpos($selector, ':') ) { return "[$selector]"; diff --git a/src/PHPCR/Util/QOM/Sql2Scanner.php b/src/PHPCR/Util/QOM/Sql2Scanner.php index a4c41078..2bc91f7d 100644 --- a/src/PHPCR/Util/QOM/Sql2Scanner.php +++ b/src/PHPCR/Util/QOM/Sql2Scanner.php @@ -70,8 +70,8 @@ public function lookupNextToken($offset = 0) public function fetchNextToken() { $token = $this->lookupNextToken(); - if ($token !== '') { - $this->curpos += 1; + if ('' !== $token) { + ++$this->curpos; } return trim($token); @@ -150,17 +150,17 @@ protected function scan($sql2) $isEscaped = false; $escapedQuotesCount = 0; $splitString = \str_split($sql2); - for ($index = 0; $index < count($splitString); $index++) { + for ($index = 0; $index < count($splitString); ++$index) { $character = $splitString[$index]; if (!$stringStartCharacter && in_array($character, [' ', "\t", "\n", "\r"], true)) { - if ($currentToken !== '') { + if ('' !== $currentToken) { $tokens[] = $currentToken; } $currentToken = ''; continue; } if (!$stringStartCharacter && in_array($character, $tokenEndChars, true)) { - if ($currentToken !== '') { + if ('' !== $currentToken) { $tokens[] = $currentToken; } $tokens[] = $character; @@ -169,8 +169,8 @@ protected function scan($sql2) } // Handling the squared brackets in queries - if (!$isEscaped && $character === '[') { - if ($currentToken !== '') { + if (!$isEscaped && '[' === $character) { + if ('' !== $currentToken) { $tokens[] = $currentToken; } $stringSize = $this->parseBrackets($sql2, $index); @@ -188,13 +188,13 @@ protected function scan($sql2) // Checking if the previous or next value is a ' to handle the weird SQL strings // This will not check if the amount of quotes is even $nextCharacter = $splitString[$index + 1] ?? ''; - if ($character === "'" && $nextCharacter === "'") { + if ("'" === $character && "'" === $nextCharacter) { $isEscaped = true; - $escapedQuotesCount++; + ++$escapedQuotesCount; continue; } // If the escaped quotes are not paired up. eg. "I'''m cool" would be a parsing error - if ($escapedQuotesCount % 2 == 1 && $stringStartCharacter !== "'") { + if (1 == $escapedQuotesCount % 2 && "'" !== $stringStartCharacter) { throw new InvalidQueryException("Syntax error: Number of single quotes to be even: $currentToken"); } if ($character === $stringStartCharacter) { @@ -213,9 +213,9 @@ protected function scan($sql2) } } } - $isEscaped = $character === '\\'; + $isEscaped = '\\' === $character; } - if ($currentToken !== '') { + if ('' !== $currentToken) { $tokens[] = $currentToken; } diff --git a/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php b/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php index 76aca66b..7e58eb0e 100644 --- a/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php +++ b/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php @@ -2,10 +2,6 @@ namespace PHPCR\Util\QOM; -use DateTime; -use Exception; -use InvalidArgumentException; -use LogicException; use PHPCR\PropertyType; use PHPCR\Query\InvalidQueryException; use PHPCR\Query\QOM\ChildNodeJoinConditionInterface; @@ -67,7 +63,7 @@ class Sql2ToQomQueryConverter * * @var string|array */ - protected $implicitSelectorName = null; + protected $implicitSelectorName; /** * @var ValueConverter @@ -77,8 +73,7 @@ class Sql2ToQomQueryConverter /** * Instantiate a converter. * - * @param QueryObjectModelFactoryInterface $factory - * @param ValueConverter $valueConverter To override default converter. + * @param ValueConverter $valueConverter to override default converter */ public function __construct(QueryObjectModelFactoryInterface $factory, ValueConverter $valueConverter = null) { @@ -92,9 +87,9 @@ public function __construct(QueryObjectModelFactoryInterface $factory, ValueConv * * @param string $sql2 * - * @throws InvalidQueryException - * * @return QueryObjectModelInterface + * + * @throws InvalidQueryException */ public function parse($sql2) { @@ -106,7 +101,7 @@ public function parse($sql2) $constraint = null; $orderings = []; - while ($this->scanner->lookupNextToken() !== '') { + while ('' !== $this->scanner->lookupNextToken()) { switch (strtoupper($this->scanner->lookupNextToken())) { case 'SELECT': $this->scanner->expectToken('SELECT'); @@ -213,9 +208,9 @@ protected function parseJoin(SourceInterface $leftSelector) /** * 6.7.6. Join type. * - * @throws InvalidQueryException - * * @return string + * + * @throws InvalidQueryException */ protected function parseJoinType() { @@ -352,18 +347,18 @@ protected function parseDescendantNodeJoinCondition() * @param ConstraintInterface $lhs Left hand side * @param int $minprec Precedence * - * @throws Exception - * * @return ConstraintInterface + * + * @throws \Exception */ protected function parseConstraint($lhs = null, $minprec = 0) { - if ($lhs === null) { + if (null === $lhs) { $lhs = $this->parsePrimaryConstraint(); } $opprec = [ - 'OR' => 1, + 'OR' => 1, 'AND' => 2, ]; @@ -391,7 +386,7 @@ protected function parseConstraint($lhs = null, $minprec = 0) // this only happens if the operator is // in the $opprec-array but there is no // "elseif"-branch here for this operator. - throw new Exception("Internal error: No action is defined for operator '$op'"); + throw new \Exception("Internal error: No action is defined for operator '$op'"); } $op = strtoupper($this->scanner->lookupNextToken()); @@ -442,14 +437,14 @@ protected function parsePrimaryConstraint() } } - if ($constraint === null) { + if (null === $constraint) { // It's not a property existence neither, then it's a comparison $constraint = $this->parseComparison(); } } // No constraint read, - if ($constraint === null) { + if (null === $constraint) { throw new InvalidQueryException("Syntax error: constraint expected in '{$this->sql2}'"); } @@ -471,9 +466,9 @@ protected function parseNot() /** * 6.7.16 Comparison. * - * @throws InvalidQueryException - * * @return ComparisonInterface + * + * @throws InvalidQueryException */ protected function parseComparison() { @@ -623,7 +618,7 @@ protected function parseDescendantNode() protected function parsePath() { $path = $this->parseLiteralValue(); - if (substr($path, 0, 1) === '[' && substr($path, -1) === ']') { + if ('[' === substr($path, 0, 1) && ']' === substr($path, -1)) { $path = substr($path, 1, -1); } @@ -640,7 +635,7 @@ protected function parsePath() protected function parseStaticOperand() { $token = $this->scanner->lookupNextToken(); - if (substr($token, 0, 1) === '$') { + if ('$' === substr($token, 0, 1)) { return $this->factory->bindVariable(substr($this->scanner->fetchNextToken(), 1)); } @@ -751,7 +746,7 @@ protected function parsePropertyValue() protected function parseCastLiteral($token) { if (!$this->scanner->tokenIs($token, 'CAST')) { - throw new LogicException('parseCastLiteral when not a CAST'); + throw new \LogicException('parseCastLiteral when not a CAST'); } $this->scanner->expectToken('('); @@ -772,7 +767,7 @@ protected function parseCastLiteral($token) try { $typeValue = PropertyType::valueFromName($type); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { throw new InvalidQueryException("Syntax error: attempting to cast to an invalid type '$type'"); } @@ -780,7 +775,7 @@ protected function parseCastLiteral($token) try { $token = $this->valueConverter->convertType($token, $typeValue, PropertyType::STRING); - } catch (Exception $e) { + } catch (\Exception $e) { throw new InvalidQueryException("Syntax error: attempting to cast string '$token' to type '$type'"); } @@ -790,8 +785,6 @@ protected function parseCastLiteral($token) /** * 6.7.34 Literal * Parse an SQL2 literal value. - * - * @return mixed */ protected function parseLiteralValue() { @@ -812,13 +805,13 @@ protected function parseLiteralValue() if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $token)) { $token .= ' 00:00:00'; } - $token = DateTime::createFromFormat('Y-m-d H:i:s', $token); + $token = \DateTime::createFromFormat('Y-m-d H:i:s', $token); } } elseif (is_numeric($token)) { - $token = strpos($token, '.') === false ? (int) $token : (float) $token; - } elseif ($token === 'true') { + $token = false === strpos($token, '.') ? (int) $token : (float) $token; + } elseif ('true' === $token) { $token = true; - } elseif ($token === 'false') { + } elseif ('false' === $token) { $token = false; } @@ -883,7 +876,7 @@ protected function parseOrdering() protected function scanColumns() { // Wildcard - if ($this->scanner->lookupNextToken() === '*') { + if ('*' === $this->scanner->lookupNextToken()) { $this->scanner->fetchNextToken(); return []; @@ -896,7 +889,7 @@ protected function scanColumns() $columns[] = $this->scanColumn(); // Are there more columns? - if ($this->scanner->lookupNextToken() !== ',') { + if (',' !== $this->scanner->lookupNextToken()) { $hasNext = false; } else { $this->scanner->fetchNextToken(); @@ -933,7 +926,7 @@ private function fetchTokenWithoutBrackets() { $token = $this->scanner->fetchNextToken(); - if (substr($token, 0, 1) === '[' && substr($token, -1) === ']') { + if ('[' === substr($token, 0, 1) && ']' === substr($token, -1)) { // Remove brackets around the selector name $token = substr($token, 1, -1); } @@ -944,7 +937,7 @@ private function fetchTokenWithoutBrackets() /** * Parse something that is expected to be a property identifier. * - * @param bool $checkSelector whether we need to ensure a valid selector. + * @param bool $checkSelector whether we need to ensure a valid selector * * @return array with selectorName and propertyName. If no selectorName is * specified, defaults to $this->defaultSelectorName @@ -954,7 +947,7 @@ private function parseIdentifier($checkSelector = true) $token = $this->fetchTokenWithoutBrackets(); // selector.property - if ($this->scanner->lookupNextToken() === '.') { + if ('.' === $this->scanner->lookupNextToken()) { $selectorName = $token; $this->scanner->fetchNextToken(); $propertyName = $this->fetchTokenWithoutBrackets(); @@ -998,10 +991,10 @@ protected function updateImplicitSelectorName($selectorName) * * @param string|null $parsedName * - * @throws InvalidQueryException if there was no explicit selector and - * there is more than one selector available. - * * @return string the selector to use + * + * @throws InvalidQueryException if there was no explicit selector and + * there is more than one selector available */ protected function ensureSelectorName($parsedName) { @@ -1044,7 +1037,7 @@ protected function scanColumn() /** * Build a single SQL2 column definition. * - * @param array $data with selector name, property name and column name. + * @param array $data with selector name, property name and column name * * @return ColumnInterface */ diff --git a/src/PHPCR/Util/TraversingItemVisitor.php b/src/PHPCR/Util/TraversingItemVisitor.php index 713df4c8..2890c555 100644 --- a/src/PHPCR/Util/TraversingItemVisitor.php +++ b/src/PHPCR/Util/TraversingItemVisitor.php @@ -7,7 +7,6 @@ use PHPCR\NodeInterface; use PHPCR\PropertyInterface; use PHPCR\RepositoryException; -use SplQueue; /** * An implementation of ItemVisitor. @@ -51,14 +50,14 @@ abstract class TraversingItemVisitor implements ItemVisitorInterface /** * Queue used to implement breadth-first traversal. * - * @var SplQueue + * @var \SplQueue */ protected $currentQueue; /** * Queue used to implement breadth-first traversal. * - * @var SplQueue + * @var \SplQueue */ protected $nextQueue; @@ -74,11 +73,11 @@ abstract class TraversingItemVisitor implements ItemVisitorInterface * * @param bool $breadthFirst if $breadthFirst is true then traversal is * done in a breadth-first manner; otherwise it is done in a - * depth-first manner (which is the default behavior). + * depth-first manner (which is the default behavior) * @param int $maxDepth the 0-based depth relative to the root node up * to which the hierarchy should be traversed (if it's -1, the * hierarchy will be traversed until there are no more children of the - * current item). + * current item) * * @api */ @@ -87,9 +86,9 @@ public function __construct($breadthFirst = false, $maxDepth = -1) $this->breadthFirst = $breadthFirst; $this->maxDepth = $maxDepth; - if ($this->breadthFirst === true) { - $this->currentQueue = new SplQueue(); - $this->nextQueue = new SplQueue(); + if (true === $this->breadthFirst) { + $this->currentQueue = new \SplQueue(); + $this->nextQueue = new \SplQueue(); } $this->currentDepth = 0; } @@ -109,11 +108,11 @@ public function setLevel($level) * visited. * * @param ItemInterface $item the Item that is accepting this - * visitor. + * visitor * @param int $depth hierarchy level of this node (the root node starts - * at depth 0). + * at depth 0) * - * @throws RepositoryException if an error occurs. + * @throws RepositoryException if an error occurs * * @api */ @@ -124,11 +123,11 @@ abstract protected function entering(ItemInterface $item, $depth); * visited. * * @param ItemInterface $item the Item that is accepting this - * visitor. + * visitor * @param int $depth hierarchy level of this property (the root node - * starts at depth 0). + * starts at depth 0) * - * @throws RepositoryException if an error occurs. + * @throws RepositoryException if an error occurs * * @api */ @@ -144,15 +143,15 @@ abstract protected function leaving(ItemInterface $item, $depth); * If this method throws, the visiting process is aborted. * * @param ItemInterface $item the Node or Property that is accepting - * this visitor. + * this visitor * - * @throws RepositoryException if an error occurs. + * @throws RepositoryException if an error occurs * * @api */ public function visit(ItemInterface $item) { - if ($this->currentDepth === 0) { + if (0 === $this->currentDepth) { $this->currentDepth = $item->getDepth(); } if ($item instanceof PropertyInterface) { @@ -169,10 +168,10 @@ public function visit(ItemInterface $item) } try { - if ($this->breadthFirst === false) { + if (false === $this->breadthFirst) { $this->entering($item, $this->currentDepth); - if ($this->maxDepth === -1 || $this->currentDepth < $this->maxDepth) { - $this->currentDepth++; + if (-1 === $this->maxDepth || $this->currentDepth < $this->maxDepth) { + ++$this->currentDepth; foreach ($item->getProperties() as $property) { /* @var $property PropertyInterface */ $property->accept($this); @@ -181,14 +180,14 @@ public function visit(ItemInterface $item) /* @var $node NodeInterface */ $node->accept($this); } - $this->currentDepth--; + --$this->currentDepth; } $this->leaving($item, $this->currentDepth); } else { $this->entering($item, $this->currentDepth); $this->leaving($item, $this->currentDepth); - if ($this->maxDepth === -1 || $this->currentDepth < $this->maxDepth) { + if (-1 === $this->maxDepth || $this->currentDepth < $this->maxDepth) { foreach ($item->getProperties() as $property) { /* @var $property PropertyInterface */ $property->accept($this); @@ -201,9 +200,9 @@ public function visit(ItemInterface $item) while (!$this->currentQueue->isEmpty() || !$this->nextQueue->isEmpty()) { if ($this->currentQueue->isEmpty()) { - $this->currentDepth++; + ++$this->currentDepth; $this->currentQueue = $this->nextQueue; - $this->nextQueue = new SplQueue(); + $this->nextQueue = new \SplQueue(); } $item = $this->currentQueue->dequeue(); $item->accept($this); diff --git a/src/PHPCR/Util/TreeWalker.php b/src/PHPCR/Util/TreeWalker.php index 2eaf6e3c..d1539e82 100644 --- a/src/PHPCR/Util/TreeWalker.php +++ b/src/PHPCR/Util/TreeWalker.php @@ -57,8 +57,6 @@ public function __construct(ItemVisitorInterface $nodeVisitor, ItemVisitorInterf /** * Add a filter to select the nodes that will be traversed. - * - * @param TreeWalkerFilterInterface $filter */ public function addNodeFilter(TreeWalkerFilterInterface $filter) { @@ -69,8 +67,6 @@ public function addNodeFilter(TreeWalkerFilterInterface $filter) /** * Add a filter to select the properties that will be traversed. - * - * @param TreeWalkerFilterInterface $filter */ public function addPropertyFilter(TreeWalkerFilterInterface $filter) { @@ -82,8 +78,6 @@ public function addPropertyFilter(TreeWalkerFilterInterface $filter) /** * Return whether a node must be traversed or not. * - * @param NodeInterface $node - * * @return bool */ protected function mustVisitNode(NodeInterface $node) @@ -100,8 +94,6 @@ protected function mustVisitNode(NodeInterface $node) /** * Return whether a node property must be traversed or not. * - * @param PropertyInterface $property - * * @return bool */ protected function mustVisitProperty(PropertyInterface $property) @@ -118,9 +110,8 @@ protected function mustVisitProperty(PropertyInterface $property) /** * Traverse a node. * - * @param NodeInterface $node - * @param int $recurse Max recursion level - * @param int $level Recursion level + * @param int $recurse Max recursion level + * @param int $level Recursion level */ public function traverse(NodeInterface $node, $recurse = -1, $level = 0): void { @@ -135,7 +126,7 @@ public function traverse(NodeInterface $node, $recurse = -1, $level = 0): void $node->accept($this->nodeVisitor); // Visit properties - if ($this->propertyVisitor !== null) { + if (null !== $this->propertyVisitor) { foreach ($node->getProperties() as $prop) { if ($this->mustVisitProperty($prop)) { if (method_exists($this->propertyVisitor, 'setLevel')) { diff --git a/src/PHPCR/Util/TreeWalkerFilterInterface.php b/src/PHPCR/Util/TreeWalkerFilterInterface.php index 41272d79..1e326056 100644 --- a/src/PHPCR/Util/TreeWalkerFilterInterface.php +++ b/src/PHPCR/Util/TreeWalkerFilterInterface.php @@ -13,10 +13,6 @@ interface TreeWalkerFilterInterface { /** * Whether to visit the passed item. - * - * @param ItemInterface $item - * - * @return mixed */ public function mustVisit(ItemInterface $item); } diff --git a/src/PHPCR/Util/UUIDHelper.php b/src/PHPCR/Util/UUIDHelper.php index 546a71db..476c1369 100644 --- a/src/PHPCR/Util/UUIDHelper.php +++ b/src/PHPCR/Util/UUIDHelper.php @@ -17,7 +17,7 @@ class UUIDHelper * * @param string $id Possible uuid * - * @return bool True if the test was passed, else false. + * @return bool true if the test was passed, else false */ public static function isUUID($id) { diff --git a/src/PHPCR/Util/ValueConverter.php b/src/PHPCR/Util/ValueConverter.php index 859cdfec..ab116639 100644 --- a/src/PHPCR/Util/ValueConverter.php +++ b/src/PHPCR/Util/ValueConverter.php @@ -4,7 +4,6 @@ use DateTime; use Exception; -use InvalidArgumentException; use PHPCR\NodeInterface; use PHPCR\PropertyInterface; use PHPCR\PropertyType; @@ -42,12 +41,12 @@ class ValueConverter * http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4.3%20From%20DATE%20To * * @param mixed $value The variable we need to know the type of - * @param bool $weak When a Node is given as $value this can be given - * as true to create a WEAKREFERENCE. - * - * @throws ValueFormatException if the type can not be determined + * @param bool $weak when a Node is given as $value this can be given + * as true to create a WEAKREFERENCE * * @return int One of the type constants + * + * @throws ValueFormatException if the type can not be determined */ public function determineType($value, $weak = false) { @@ -107,12 +106,12 @@ public function determineType($value, $weak = false) * @param int $type Target type to convert into. One of the type constants in PropertyType * @param int $srcType Source type to convert from, if not specified this is automatically determined, which will miss the string based types that are not strings (DECIMAL, NAME, PATH, URI) * - * @throws ValueFormatException is thrown if the specified value cannot be converted to the specified type - * @throws RepositoryException if the specified Node is not referenceable, the current Session is no longer active, or another error occurs. - * @throws InvalidArgumentException if the specified DateTime value cannot be expressed in the ISO 8601-based format defined in the JCR 2.0 specification and the implementation does not support dates incompatible with that format. - * * @return mixed the value casted into the proper format (throws an exception if conversion is not possible) * + * @throws ValueFormatException is thrown if the specified value cannot be converted to the specified type + * @throws RepositoryException if the specified Node is not referenceable, the current Session is no longer active, or another error occurs + * @throws \InvalidArgumentException if the specified DateTime value cannot be expressed in the ISO 8601-based format defined in the JCR 2.0 specification and the implementation does not support dates incompatible with that format. + * * @see http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4%20Property%20Type%20Conversion */ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) @@ -154,9 +153,10 @@ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) case PropertyType::STRING: switch ($srcType) { case PropertyType::DATE: - if (!$value instanceof DateTime) { + if (!$value instanceof \DateTime) { throw new RepositoryException('Cannot convert a date that is not a \DateTime instance to string'); } + /* @var $value DateTime */ // Milliseconds formatting is not possible in PHP so we // construct it by cutting microseconds to 3 positions. @@ -175,10 +175,12 @@ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) if (is_resource($value)) { throw new ValueFormatException('Inconsistency: Non-binary property should not have resource stream value'); } + // TODO: how can we provide ValueFormatException on failure? invalid casting leads to 'catchable fatal error' instead of exception return (string) $value; } + // no break case PropertyType::BINARY: if (is_resource($value)) { return $value; @@ -201,7 +203,7 @@ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) case PropertyType::DECIMAL: return (int) $value; case PropertyType::DATE: - if (!$value instanceof DateTime) { + if (!$value instanceof \DateTime) { throw new RepositoryException('something weird'); } /* @var $value DateTime */ @@ -222,7 +224,7 @@ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) case PropertyType::DECIMAL: return (float) $value; case PropertyType::DATE: - if (!$value instanceof DateTime) { + if (!$value instanceof \DateTime) { throw new RepositoryException('something weird'); } @@ -239,19 +241,19 @@ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) switch ($srcType) { case PropertyType::STRING: case PropertyType::DATE: - if ($value instanceof DateTime) { + if ($value instanceof \DateTime) { return $value; } try { - return new DateTime($value); - } catch (Exception $e) { + return new \DateTime($value); + } catch (\Exception $e) { throw new ValueFormatException("String '$value' is not a valid date", 0, $e); } case PropertyType::LONG: case PropertyType::DOUBLE: case PropertyType::DECIMAL: - $datetime = new DateTime(); + $datetime = new \DateTime(); $datetime = $datetime->setTimestamp(round($value)); return $datetime; @@ -320,7 +322,7 @@ public function convertType($value, $type, $srcType = PropertyType::UNDEFINED) case PropertyType::REFERENCE: case PropertyType::WEAKREFERENCE: if (empty($value)) { - //TODO check if string is valid uuid + // TODO check if string is valid uuid throw new ValueFormatException('Value "'.var_export($value, true).'" is not a valid unique id'); } diff --git a/tests/PHPCR/Tests/Stubs/MockNode.php b/tests/PHPCR/Tests/Stubs/MockNode.php index e0249394..ea937214 100644 --- a/tests/PHPCR/Tests/Stubs/MockNode.php +++ b/tests/PHPCR/Tests/Stubs/MockNode.php @@ -2,9 +2,8 @@ namespace PHPCR\Tests\Stubs; -use Iterator; use PHPCR\NodeInterface; -abstract class MockNode implements Iterator, NodeInterface +abstract class MockNode implements \Iterator, NodeInterface { } diff --git a/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php b/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php index 7cd46605..97f696f0 100644 --- a/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php +++ b/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php @@ -2,9 +2,8 @@ namespace PHPCR\Tests\Stubs; -use Iterator; use PHPCR\NodeType\NodeTypeManagerInterface; -abstract class MockNodeTypeManager implements Iterator, NodeTypeManagerInterface +abstract class MockNodeTypeManager implements \Iterator, NodeTypeManagerInterface { } diff --git a/tests/PHPCR/Tests/Stubs/MockRow.php b/tests/PHPCR/Tests/Stubs/MockRow.php index 45077223..298e2bef 100644 --- a/tests/PHPCR/Tests/Stubs/MockRow.php +++ b/tests/PHPCR/Tests/Stubs/MockRow.php @@ -2,9 +2,8 @@ namespace PHPCR\Tests\Stubs; -use Iterator; use PHPCR\Query\RowInterface; -abstract class MockRow implements Iterator, RowInterface +abstract class MockRow implements \Iterator, RowInterface { } diff --git a/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php b/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php index 86fd7479..7741efe6 100644 --- a/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php +++ b/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php @@ -7,7 +7,7 @@ class BufferReaderTest extends TestCase { - public function test__construct(): void + public function testConstruct(): void { $buffer = "Some random\nor\r\nstring"; $reader = new BufferReader($buffer); @@ -92,7 +92,7 @@ public function test__construct(): void $this->assertEquals($reader->getEofMarker(), $reader->forward()); } - public function test__constructEmptyString() + public function testConstructEmptyString() { $reader = new BufferReader(''); diff --git a/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php b/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php index 5d3d1a2d..e7fed571 100644 --- a/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php +++ b/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\CND\Reader; -use InvalidArgumentException; use PHPCR\Util\CND\Reader\FileReader; use PHPUnit\Framework\TestCase; @@ -48,9 +47,9 @@ public function setUp(): void ); } - public function test__construct_fileNotFound() + public function testConstructFileNotFound() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); new FileReader('unexisting_file'); } @@ -65,7 +64,7 @@ public function testGetNextChar() $curLine = 1; $curCol = 1; - for ($i = 0; $i < count($this->chars); $i++) { + for ($i = 0; $i < count($this->chars); ++$i) { $peek = $this->reader->currentChar(); if ($peek === $this->reader->getEofMarker()) { @@ -80,11 +79,11 @@ public function testGetNextChar() $this->assertFalse($this->reader->isEof()); // Assert isEol is true at end of the lines - if ($peek === "\n") { - $curLine++; + if ("\n" === $peek) { + ++$curLine; $curCol = 1; } else { - $curCol++; + ++$curCol; } // Assert the next character is the expected one diff --git a/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php b/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php index 59f9377d..53c5212a 100644 --- a/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php +++ b/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\CND\Scanner; -use ArrayIterator; use PHPCR\Util\CND\Reader\FileReader; use PHPCR\Util\CND\Scanner\Context\DefaultScannerContext; use PHPCR\Util\CND\Scanner\GenericScanner; @@ -14,7 +13,6 @@ class GenericScannerTest extends TestCase { protected $expectedTokens = [ - // [Token::TK_SYMBOL, '<'], [Token::TK_SYMBOL, '?'], @@ -110,7 +108,7 @@ public function setUp(): void { $this->expectedTokensNoEmptyToken = []; foreach ($this->expectedTokens as $token) { - if ($token[0] !== Token::TK_NEWLINE && $token[0] !== Token::TK_WHITESPACE) { + if (Token::TK_NEWLINE !== $token[0] && Token::TK_WHITESPACE !== $token[0]) { $this->expectedTokensNoEmptyToken[] = $token; } } @@ -144,7 +142,7 @@ protected function assertTokens($tokens, TokenQueue $queue) { $queue->reset(); - $it = new ArrayIterator($tokens); + $it = new \ArrayIterator($tokens); $token = $queue->peek(); diff --git a/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php b/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php index 8f81190b..272ce1e4 100644 --- a/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php +++ b/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php @@ -17,7 +17,7 @@ public function setUp(): void $this->token = new Token(123, 'foobar'); } - public function test__construct() + public function testConstruct() { $this->assertSame(123, $this->token->type); $this->assertSame('foobar', $this->token->data); @@ -33,7 +33,7 @@ public function testGetType() $this->assertEquals(123, $this->token->getType()); } - public function test__toString() + public function testToString() { $this->assertEquals('TOKEN(123, \'foobar\', 0, 0)', $this->token->__toString()); } diff --git a/tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php index f935b7df..26c13f6f 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php @@ -84,7 +84,7 @@ public function setUp(): void ->getMock(); $this->helperSet = new HelperSet([ - 'phpcr' => new PhpcrHelper($this->session), + 'phpcr' => new PhpcrHelper($this->session), 'phpcr_console_dumper' => $this->dumperHelper, ]); diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php index 993d4864..c9aee706 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\Console\Command; -use Exception; use PHPCR\ItemNotFoundException; use PHPCR\Util\Console\Command\NodeDumpCommand; use PHPCR\Util\TreeWalker; @@ -71,7 +70,7 @@ public function testCommandIdentifier() public function testInvalidRefFormat() { - $this->expectException(Exception::class); + $this->expectException(\Exception::class); $this->executeCommand('phpcr:node:dump', ['--ref-format' => 'xy']); $this->fail('invalid ref-format did not produce exception'); diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodeRemoveCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodeRemoveCommandTest.php index c103ee42..7edbd102 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/NodeRemoveCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/NodeRemoveCommandTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\Console\Command; -use LogicException; use PHPCR\Util\Console\Command\NodeRemoveCommand; class NodeRemoveCommandTest extends BaseCommandTest @@ -22,17 +21,17 @@ public function testRemove() $this->executeCommand('phpcr:node:remove', [ '--force' => true, - 'path' => '/cms', + 'path' => '/cms', ]); } public function testRemoveRoot() { - $this->expectException(LogicException::class); + $this->expectException(\LogicException::class); $this->executeCommand('phpcr:node:remove', [ '--force' => true, - 'path' => '/', + 'path' => '/', ]); } } diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php index 0bbb59ac..30cc7fae 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\Console\Command; -use Exception; use PHPCR\NodeType\NodeTypeInterface; use PHPCR\PathNotFoundException; use PHPCR\Tests\Stubs\MockNode; @@ -58,7 +57,7 @@ public function testTouch() throw new PathNotFoundException(); } - throw new Exception('Unexpected '.$path); + throw new \Exception('Unexpected '.$path); }); $this->node1->expects($this->once()) @@ -104,12 +103,12 @@ public function testUpdate() }); $this->executeCommand('phpcr:node:touch', [ - 'path' => '/cms', - '--set-prop' => ['foo=bar'], - '--remove-prop' => ['bar'], - '--add-mixin' => ['foo:bar'], + 'path' => '/cms', + '--set-prop' => ['foo=bar'], + '--remove-prop' => ['bar'], + '--add-mixin' => ['foo:bar'], '--remove-mixin' => ['bar:foo'], - '--dump' => true, + '--dump' => true, ]); } } diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php index 542fe109..a05ea5a5 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\Console\Command; -use InvalidArgumentException; use PHPCR\Query\QueryInterface; use PHPCR\Util\Console\Command\NodesUpdateCommand; use PHPUnit\Framework\MockObject\MockObject; @@ -26,16 +25,16 @@ public function provideNodeUpdate() { return [ // No query specified - [['exception' => InvalidArgumentException::class]], + [['exception' => \InvalidArgumentException::class]], // Specify query [['query' => 'SELECT * FROM nt:unstructured WHERE foo="bar"']], // Set, remote properties and mixins [[ - 'setProp' => [['foo', 'bar']], - 'removeProp' => ['bar'], - 'addMixin' => ['mixin1'], + 'setProp' => [['foo', 'bar']], + 'removeProp' => ['bar'], + 'addMixin' => ['mixin1'], 'removeMixin' => ['mixin1'], - 'query' => 'SELECT * FROM nt:unstructured', + 'query' => 'SELECT * FROM nt:unstructured', ]], ]; } @@ -72,12 +71,12 @@ protected function setupQueryManager($options) public function testNodeUpdate($options) { $options = array_merge([ - 'query' => null, - 'setProp' => [], - 'removeProp' => [], - 'addMixin' => [], + 'query' => null, + 'setProp' => [], + 'removeProp' => [], + 'addMixin' => [], 'removeMixin' => [], - 'exception' => null, + 'exception' => null, ], $options); if ($options['exception']) { @@ -87,12 +86,12 @@ public function testNodeUpdate($options) $this->setupQueryManager($options); $args = [ - '--query' => $options['query'], + '--query' => $options['query'], '--no-interaction' => true, - '--set-prop' => [], - '--remove-prop' => [], - '--add-mixin' => [], - '--remove-mixin' => [], + '--set-prop' => [], + '--remove-prop' => [], + '--add-mixin' => [], + '--remove-mixin' => [], ]; $setPropertyArguments = []; @@ -133,9 +132,9 @@ public function testNodeUpdate($options) public function testApplyClosure() { $args = [ - '--query' => 'SELECT foo FROM bar', + '--query' => 'SELECT foo FROM bar', '--no-interaction' => true, - '--apply-closure' => [ + '--apply-closure' => [ '$session->getNodeByIdentifier("/foo"); $node->setProperty("foo", "bar");', function ($session, $node) { $node->setProperty('foo', 'bar'); diff --git a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceCreateCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceCreateCommandTest.php index 7df686b8..34f86086 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceCreateCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceCreateCommandTest.php @@ -75,7 +75,7 @@ public function testCreateExisting() $tester = $this->executeCommand( 'phpcr:workspace:create', [ - 'name' => 'test', + 'name' => 'test', '--ignore-existing' => true, ], 0 diff --git a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceDeleteCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceDeleteCommandTest.php index 9808db4b..ebd841fa 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceDeleteCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceDeleteCommandTest.php @@ -38,7 +38,7 @@ public function testDelete() ->with('test_workspace'); $ct = $this->executeCommand('phpcr:workspace:delete', [ - 'name' => 'test_workspace', + 'name' => 'test_workspace', '--force' => 'true', ]); @@ -56,7 +56,7 @@ public function testDeleteNonexistent() ->willReturn(['default', 'other']); $ct = $this->executeCommand('phpcr:workspace:delete', [ - 'name' => 'test_workspace', + 'name' => 'test_workspace', '--force' => 'true', ]); diff --git a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceImportCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceImportCommandTest.php index d2b5ebd9..5d2958c9 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceImportCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceImportCommandTest.php @@ -53,7 +53,7 @@ public function testImportUuidBehaviorThrow() ->with('/', 'test_import.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW); $ct = $this->executeCommand('phpcr:workspace:import', [ - 'filename' => 'test_import.xml', + 'filename' => 'test_import.xml', '--uuid-behavior' => 'throw', ]); diff --git a/tests/PHPCR/Tests/Util/Console/Helper/PhpcrConsoleDumperHelperTest.php b/tests/PHPCR/Tests/Util/Console/Helper/PhpcrConsoleDumperHelperTest.php index 057b3a6e..6c4b97dc 100644 --- a/tests/PHPCR/Tests/Util/Console/Helper/PhpcrConsoleDumperHelperTest.php +++ b/tests/PHPCR/Tests/Util/Console/Helper/PhpcrConsoleDumperHelperTest.php @@ -31,9 +31,9 @@ public function provideHelper() public function testGetTreeWalker($options) { $options = array_merge([ - 'dump_uuids' => false, - 'ref_format' => 'uuid', - 'show_props' => false, + 'dump_uuids' => false, + 'ref_format' => 'uuid', + 'show_props' => false, 'show_sys_nodes' => false, ], $options); @@ -45,7 +45,7 @@ public function testGetTreeWalker($options) $propVisitorProp->setAccessible(true); $propVisitor = $propVisitorProp->getValue($tw); - if ($options['show_props'] === true) { + if (true === $options['show_props']) { $this->assertInstanceOf(ConsoleDumperPropertyVisitor::class, $propVisitor); } else { $this->assertNull($propVisitor); diff --git a/tests/PHPCR/Tests/Util/NodeHelperTest.php b/tests/PHPCR/Tests/Util/NodeHelperTest.php index bebad5e2..a3659292 100644 --- a/tests/PHPCR/Tests/Util/NodeHelperTest.php +++ b/tests/PHPCR/Tests/Util/NodeHelperTest.php @@ -139,7 +139,7 @@ public function testCalculateOrderBeforeSwapLast() $expected = [ 'three' => null, - 'two' => 'four', // TODO: this is an unnecessary but harmless NOOP. we should try to eliminate + 'two' => 'four', // TODO: this is an unnecessary but harmless NOOP. we should try to eliminate ]; $this->assertEquals($expected, $reorders); @@ -154,7 +154,7 @@ public function testCalculateOrderBeforeSwap() $expected = [ 'three' => 'two', - 'two' => null, + 'two' => null, ]; $this->assertEquals($expected, $reorders); @@ -169,8 +169,8 @@ public function testCalculateOrderBeforeReverse() $expected = [ 'three' => 'two', - 'two' => 'one', - 'one' => null, + 'two' => 'one', + 'one' => null, ]; $this->assertEquals($expected, $reorders); } @@ -183,8 +183,8 @@ public function testCalculateOrderBeforeDeleted() $reorders = NodeHelper::calculateOrderBefore($old, $new); $expected = [ - 'two' => null, - 'one' => 'three', // TODO: this is an unnecessary but harmless NOOP. we should try to eliminate + 'two' => null, + 'one' => 'three', // TODO: this is an unnecessary but harmless NOOP. we should try to eliminate ]; $this->assertEquals($expected, $reorders); @@ -197,7 +197,7 @@ public function testBenchmarkOrderBeforeArray() { $nodes = []; - for ($i = 0; $i < 100000; $i++) { + for ($i = 0; $i < 100000; ++$i) { $nodes[] = 'test'.$i; } diff --git a/tests/PHPCR/Tests/Util/PathHelperTest.php b/tests/PHPCR/Tests/Util/PathHelperTest.php index 14d09116..cc7ec87c 100644 --- a/tests/PHPCR/Tests/Util/PathHelperTest.php +++ b/tests/PHPCR/Tests/Util/PathHelperTest.php @@ -6,7 +6,6 @@ use PHPCR\RepositoryException; use PHPCR\Util\PathHelper; use PHPUnit\Framework\TestCase; -use stdClass; class PathHelperTest extends TestCase { @@ -172,7 +171,7 @@ public static function dataproviderNormalizePathInvalid() ['bar'], ['/foo/bar/'], [''], - [new stdClass()], + [new \stdClass()], ]; } @@ -219,7 +218,7 @@ public static function dataproviderAbsolutizePathInvalid() ['', '/context', false], [null, '/context', false], ['foo', null, false], - [new stdClass(), '/context', false], + [new \stdClass(), '/context', false], ['foo[2]', '/bar', true], ]; } diff --git a/tests/PHPCR/Tests/Util/QOM/QueryBuilderTest.php b/tests/PHPCR/Tests/Util/QOM/QueryBuilderTest.php index a96ef099..7b50c429 100644 --- a/tests/PHPCR/Tests/Util/QOM/QueryBuilderTest.php +++ b/tests/PHPCR/Tests/Util/QOM/QueryBuilderTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\QOM; -use InvalidArgumentException; use PHPCR\Query\QOM\ConstraintInterface; use PHPCR\Query\QOM\DynamicOperandInterface; use PHPCR\Query\QOM\QueryObjectModelConstantsInterface; @@ -13,7 +12,6 @@ use PHPCR\Util\QOM\QueryBuilder; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use RuntimeException; class QueryBuilderTest extends TestCase { @@ -82,7 +80,7 @@ public function testAddOrderByLowercase() public function testAddOrderByInvalid() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $dynamicOperand = $this->createDynamicOperandMock(); @@ -244,7 +242,7 @@ private function createSameNodeJoinConditionMock() public function testInvalidJoin() { - $this->expectException(RuntimeException::class); + $this->expectException(\RuntimeException::class); $source = $this->createSourceMock(); $joinCondition = $this->createSameNodeJoinConditionMock(); diff --git a/tests/PHPCR/Tests/Util/QOM/Sql1GeneratorTest.php b/tests/PHPCR/Tests/Util/QOM/Sql1GeneratorTest.php index aa0a7aa9..b3f37199 100644 --- a/tests/PHPCR/Tests/Util/QOM/Sql1GeneratorTest.php +++ b/tests/PHPCR/Tests/Util/QOM/Sql1GeneratorTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\QOM; -use DateTime; use PHPCR\Util\QOM\Sql1Generator; use PHPCR\Util\ValueConverter; use PHPUnit\Framework\TestCase; @@ -27,7 +26,7 @@ public function testLiteral() public function testDateTimeLiteral() { - $literal = $this->generator->evalLiteral(new DateTime('2011-12-23T00:00:00.000+00:00')); + $literal = $this->generator->evalLiteral(new \DateTime('2011-12-23T00:00:00.000+00:00')); $this->assertEquals("TIMESTAMP '2011-12-23T00:00:00.000+00:00'", $literal); } diff --git a/tests/PHPCR/Tests/Util/QOM/Sql2GeneratorTest.php b/tests/PHPCR/Tests/Util/QOM/Sql2GeneratorTest.php index f28dff48..1dac2525 100644 --- a/tests/PHPCR/Tests/Util/QOM/Sql2GeneratorTest.php +++ b/tests/PHPCR/Tests/Util/QOM/Sql2GeneratorTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util\QOM; -use DateTime; use PHPCR\Util\QOM\Sql2Generator; use PHPCR\Util\ValueConverter; @@ -26,7 +25,7 @@ public function testLiteral() public function testDateTimeLiteral() { - $literal = $this->generator->evalLiteral(new DateTime('2011-12-23T00:00:00.000+00:00')); + $literal = $this->generator->evalLiteral(new \DateTime('2011-12-23T00:00:00.000+00:00')); $this->assertEquals("CAST('2011-12-23T00:00:00.000+00:00' AS DATE)", $literal); } diff --git a/tests/PHPCR/Tests/Util/QOM/Sql2ScannerTest.php b/tests/PHPCR/Tests/Util/QOM/Sql2ScannerTest.php index 4fca5913..b4627bbb 100644 --- a/tests/PHPCR/Tests/Util/QOM/Sql2ScannerTest.php +++ b/tests/PHPCR/Tests/Util/QOM/Sql2ScannerTest.php @@ -185,7 +185,6 @@ public function testThrowingErrorOnUnclosedString() * Function to assert that the tokens the scanner finds match the expected output * and the entire expected output is consumed. * - * @param Sql2Scanner $scanner * @param array $expected */ private function expectTokensFromScanner(Sql2Scanner $scanner, array $expected) diff --git a/tests/PHPCR/Tests/Util/ValueConverterTest.php b/tests/PHPCR/Tests/Util/ValueConverterTest.php index 65002a7c..e69ed968 100644 --- a/tests/PHPCR/Tests/Util/ValueConverterTest.php +++ b/tests/PHPCR/Tests/Util/ValueConverterTest.php @@ -2,7 +2,6 @@ namespace PHPCR\Tests\Util; -use DateTime; use PHPCR\PropertyType; use PHPCR\RepositoryException; use PHPCR\Tests\Stubs\MockNode; @@ -49,7 +48,7 @@ public function dataConversionMatrix() fwrite($uuidStream, '38b7cf18-c417-477a-af0b-c1e92a290c9a'); rewind($uuidStream); - $datetimeLong = new DateTime(); + $datetimeLong = new \DateTime(); $datetimeLong->setTimestamp(123); $nodeMock = $this->createMock(MockNode::class); @@ -70,7 +69,7 @@ public function dataConversionMatrix() ['test string', PropertyType::STRING, 0.0, PropertyType::DOUBLE], ['249.39', PropertyType::STRING, 249.39, PropertyType::DOUBLE], ['test string', PropertyType::STRING, null, PropertyType::DATE], - ['17.12.2010 GMT', PropertyType::STRING, new DateTime('17.12.2010 GMT'), PropertyType::DATE], + ['17.12.2010 GMT', PropertyType::STRING, new \DateTime('17.12.2010 GMT'), PropertyType::DATE], ['test string', PropertyType::STRING, true, PropertyType::BOOLEAN], ['false', PropertyType::STRING, true, PropertyType::BOOLEAN], ['', PropertyType::STRING, false, PropertyType::BOOLEAN], @@ -91,7 +90,7 @@ public function dataConversionMatrix() [$stream, PropertyType::BINARY, 0.0, PropertyType::DOUBLE], [$numberStream, PropertyType::BINARY, 123.456, PropertyType::DOUBLE], [$stream, PropertyType::BINARY, null, PropertyType::DATE], - [$dateStream, PropertyType::BINARY, new DateTime('17.12.2010 GMT'), PropertyType::DATE], + [$dateStream, PropertyType::BINARY, new \DateTime('17.12.2010 GMT'), PropertyType::DATE], [$stream, PropertyType::BINARY, true, PropertyType::BOOLEAN], [$nameStream, PropertyType::BINARY, 'test', PropertyType::NAME], // TODO: should we move UUIDHelper to phpcr so we can check in PropertyType? [$stream, PropertyType::STRING, null, PropertyType::REFERENCE], @@ -268,10 +267,7 @@ public function dataConversionMatrix() /** * Skip binary target as its a special case. * - * @param mixed $value - * @param int $srcType PropertyType constant to convert from - * @param $expected - * @param $targetType + * @param int $srcType PropertyType constant to convert from * * @dataProvider dataConversionMatrix */ @@ -286,9 +282,9 @@ public function testConvertType($value, $srcType, $expected, $targetType) $this->assertTrue(true); // make it assert something } } else { - if ($expected instanceof DateTime) { + if ($expected instanceof \DateTime) { $result = $this->valueConverter->convertType($value, $targetType, $srcType); - $this->assertInstanceOf(DateTime::class, $result); + $this->assertInstanceOf(\DateTime::class, $result); $this->assertEquals($expected->getTimestamp(), $result->getTimestamp()); } else { $this->assertSame($expected, $this->valueConverter->convertType($value, $targetType, $srcType)); @@ -308,11 +304,11 @@ public function testConvertTypeToBinary() $string = stream_get_contents($stream); $this->assertEquals('test string', $string); - $date = new DateTime('20.12.2012'); + $date = new \DateTime('20.12.2012'); $stream = $this->valueConverter->convertType($date, PropertyType::BINARY); $this->assertIsResource($stream); $string = stream_get_contents($stream); - $readDate = new DateTime($string); + $readDate = new \DateTime($string); $this->assertEquals($date->getTimestamp(), $readDate->getTimestamp()); $stream = fopen('php://memory', '+rw'); @@ -335,8 +331,8 @@ public function testConvertTypeArray() $this->assertIsArray($result); $this->assertCount(2, $result); - $this->assertInstanceOf(DateTime::class, $result[0]); - $this->assertInstanceOf(DateTime::class, $result[1]); + $this->assertInstanceOf(\DateTime::class, $result[0]); + $this->assertInstanceOf(\DateTime::class, $result[1]); $this->assertEquals('2012-01-10', $result[0]->format('Y-m-d')); $this->assertEquals('2012-02-12', $result[1]->format('Y-m-d')); @@ -347,13 +343,13 @@ public function testConvertTypeArray() public function testConvertTypeAutodetect() { - $date = new DateTime('2012-10-10'); + $date = new \DateTime('2012-10-10'); $result = $this->valueConverter->convertType($date, PropertyType::STRING); - $result = new DateTime($result); + $result = new \DateTime($result); $this->assertEquals($date->getTimestamp(), $result->getTimestamp()); $result = $this->valueConverter->convertType('2012-03-13T21:00:55.000+01:00', PropertyType::DATE); - $this->assertInstanceOf(DateTime::class, $result); + $this->assertInstanceOf(\DateTime::class, $result); $this->assertEquals(1331668855, $result->getTimestamp()); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index cabe0864..ac7baf3d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,7 +5,7 @@ * @author Nacho Martín * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License 2.0 * - * @link http://phpcr.github.io/ + * @see http://phpcr.github.io/ */ // $file2 for run tests if phpcr-utils lib inside of vendor directory.