diff --git a/src/PHPCR/Util/CND/Parser/AbstractParser.php b/src/PHPCR/Util/CND/Parser/AbstractParser.php index d2edb48..1dfa587 100644 --- a/src/PHPCR/Util/CND/Parser/AbstractParser.php +++ b/src/PHPCR/Util/CND/Parser/AbstractParser.php @@ -23,9 +23,6 @@ */ abstract class AbstractParser { - /** - * The token queue. - */ protected TokenQueue $tokenQueue; /** @@ -105,7 +102,7 @@ protected function expectToken(int $type, string $data = null): Token * @param int $type The expected token type * @param string|null $data The expected token data or null */ - protected function checkAndExpectToken(int $type, string $data = null): bool|Token + protected function checkAndExpectToken(int $type, string $data = null): false|Token { if ($this->checkToken($type, $data)) { $token = $this->tokenQueue->peek(); diff --git a/src/PHPCR/Util/CND/Parser/CndParser.php b/src/PHPCR/Util/CND/Parser/CndParser.php index bf789ee..58a76d8 100644 --- a/src/PHPCR/Util/CND/Parser/CndParser.php +++ b/src/PHPCR/Util/CND/Parser/CndParser.php @@ -68,12 +68,12 @@ final class CndParser extends AbstractParser /** * @var string[] */ - protected array $namespaces = []; + private array $namespaces = []; /** * @var string[] */ - protected array $nodeTypes = []; + private array $nodeTypes = []; public function __construct(NodeTypeManagerInterface $ntm) { @@ -142,7 +142,7 @@ private function parse(ReaderInterface $reader): array * Prefix ::= String * Uri ::= String */ - protected function parseNamespaceMapping(): void + private function parseNamespaceMapping(): void { $this->expectToken(Token::TK_SYMBOL, '<'); $prefix = $this->parseCndString(); @@ -162,7 +162,7 @@ protected function parseNamespaceMapping(): void * [NodeTypeAttribute {NodeTypeAttribute}] * {PropertyDef | ChildNodeDef} */ - protected function parseNodeType(): void + private function parseNodeType(): void { $nodeType = $this->ntm->createNodeTypeTemplate(); $this->parseNodeTypeName($nodeType); @@ -183,7 +183,7 @@ protected function parseNodeType(): void * * NodeTypeName ::= '[' String ']' */ - protected function parseNodeTypeName(NodeTypeTemplateInterface $nodeType): void + private function parseNodeTypeName(NodeTypeTemplateInterface $nodeType): void { $this->expectToken(Token::TK_SYMBOL, '['); $name = $this->parseCndString(); @@ -200,7 +200,7 @@ protected function parseNodeTypeName(NodeTypeTemplateInterface $nodeType): void * * Supertypes ::= '>' (StringList | '?') */ - protected function parseSupertypes(NodeTypeTemplateInterface $nodeType): void + private function parseSupertypes(NodeTypeTemplateInterface $nodeType): void { $this->expectToken(Token::TK_SYMBOL, '>'); @@ -243,7 +243,7 @@ protected function parseSupertypes(NodeTypeTemplateInterface $nodeType): void * Query ::= ('noquery' | 'nq') | ('query' | 'q' ) * PrimaryItem ::= ('primaryitem'| '!')(String | '?') */ - protected function parseNodeTypeAttributes(NodeTypeTemplateInterface $nodeType): void + private function parseNodeTypeAttributes(NodeTypeTemplateInterface $nodeType): void { while (true) { if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->ORDERABLE)) { @@ -284,7 +284,7 @@ protected function parseNodeTypeAttributes(NodeTypeTemplateInterface $nodeType): * * {PropertyDef | ChildNodeDef} */ - protected function parseChildrenAndAttributes(NodeTypeTemplateInterface $nodeType): void + private function parseChildrenAndAttributes(NodeTypeTemplateInterface $nodeType): void { while (true) { if ($this->checkToken(Token::TK_SYMBOL, '-')) { @@ -310,7 +310,7 @@ protected function parseChildrenAndAttributes(NodeTypeTemplateInterface $nodeTyp * [ValueConstraints] * PropertyName ::= '-' String */ - protected function parsePropDef(NodeTypeTemplateInterface $nodeType): void + private function parsePropDef(NodeTypeTemplateInterface $nodeType): void { $this->expectToken(Token::TK_SYMBOL, '-'); @@ -364,7 +364,7 @@ protected function parsePropDef(NodeTypeTemplateInterface $nodeType): void * 'DECIMAL' | 'URI' | 'UNDEFINED' | '*' | * '?') ')' */ - protected function parsePropertyType(PropertyDefinitionTemplateInterface $property): void + private function parsePropertyType(PropertyDefinitionTemplateInterface $property): void { $types = ['STRING', 'BINARY', 'LONG', 'DOUBLE', 'BOOLEAN', 'DATE', 'NAME', 'PATH', 'REFERENCE', 'WEAKREFERENCE', 'DECIMAL', 'URI', 'UNDEFINED', '*', '?', ]; @@ -388,7 +388,7 @@ protected function parsePropertyType(PropertyDefinitionTemplateInterface $proper * * DefaultValues ::= '=' (StringList | '?') */ - protected function parseDefaultValue(PropertyDefinitionTemplateInterface $property): void + private function parseDefaultValue(PropertyDefinitionTemplateInterface $property): void { if ($this->checkAndExpectToken(Token::TK_SYMBOL, '?')) { $list = ['?']; @@ -406,7 +406,7 @@ protected function parseDefaultValue(PropertyDefinitionTemplateInterface $proper * * ValueConstraints ::= '<' (StringList | '?') */ - protected function parseValueConstraints(PropertyDefinitionTemplateInterface $property): void + private function parseValueConstraints(PropertyDefinitionTemplateInterface $property): void { $this->expectToken(Token::TK_SYMBOL, '<'); @@ -473,7 +473,7 @@ protected function parseValueConstraints(PropertyDefinitionTemplateInterface $pr * NoFullText ::= ('nofulltext' | 'nof') ['?'] * NoQueryOrder ::= ('noqueryorder' | 'nqord') ['?'] */ - protected function parsePropertyAttributes(NodeTypeTemplateInterface $parentType, PropertyDefinitionTemplateInterface $property): void + private function parsePropertyAttributes(NodeTypeTemplateInterface $parentType, PropertyDefinitionTemplateInterface $property): void { $opvSeen = false; while (true) { @@ -527,7 +527,7 @@ protected function parsePropertyAttributes(NodeTypeTemplateInterface $parentType * RequiredTypes ::= '(' (StringList | '?') ')' * DefaultType ::= '=' (String | '?') */ - protected function parseChildNodeDef(NodeTypeTemplateInterface $nodeType): void + private function parseChildNodeDef(NodeTypeTemplateInterface $nodeType): void { $this->expectToken(Token::TK_SYMBOL, '+'); $childType = $this->ntm->createNodeDefinitionTemplate(); @@ -593,7 +593,7 @@ protected function parseChildNodeDef(NodeTypeTemplateInterface $nodeType): void * 'IGNORE' | 'ABORT' | ('OPV' '?') * Sns ::= ('sns' | '*') ['?'] */ - protected function parseChildNodeAttributes( + private function parseChildNodeAttributes( NodeTypeTemplateInterface $parentType, NodeDefinitionTemplateInterface $childType ): void { @@ -627,7 +627,7 @@ protected function parseChildNodeAttributes( * * @return string[] */ - protected function parseCndStringList(): array + private function parseCndStringList(): array { $strings = []; @@ -658,7 +658,7 @@ protected function parseCndStringList(): array * * TODO: check \n, \r, \t are valid in CND strings! */ - protected function parseCndString(): string + private function parseCndString(): string { $string = ''; $lastType = null; @@ -714,9 +714,9 @@ protected function parseCndString(): string * (('''Operator {','Operator}''') | '?') * Operator ::= '=' | '<>' | '<' | '<=' | '>' | '>=' | 'LIKE' * - * @return array + * @return array */ - protected function parseQueryOpsAttribute() + private function parseQueryOpsAttribute(): array { if ($this->checkAndExpectToken(Token::TK_SYMBOL, '?')) { // this denotes a variant, whatever that is @@ -732,10 +732,7 @@ protected function parseQueryOpsAttribute() return $ops; } - /** - * Parse a query operator. - */ - protected function parseQueryOperator(): bool|string + private function parseQueryOperator(): bool|string { $token = $this->tokenQueue->peek(); $data = $token->getData(); diff --git a/src/PHPCR/Util/CND/Scanner/GenericScanner.php b/src/PHPCR/Util/CND/Scanner/GenericScanner.php index 1396b4d..d03bb90 100644 --- a/src/PHPCR/Util/CND/Scanner/GenericScanner.php +++ b/src/PHPCR/Util/CND/Scanner/GenericScanner.php @@ -93,11 +93,6 @@ protected function consumeNewLine(ReaderInterface $reader): bool return false; } - /** - * Detect and consume strings. - * - * @throws ScannerException - */ protected function consumeString(ReaderInterface $reader): bool { $curDelimiter = $reader->currentChar(); @@ -121,9 +116,6 @@ protected function consumeString(ReaderInterface $reader): bool return false; } - /** - * Detect and consume comments. - */ protected function consumeComments(ReaderInterface $reader): bool { if ($this->consumeBlockComments($reader)) { @@ -133,11 +125,6 @@ protected function consumeComments(ReaderInterface $reader): bool return $this->consumeLineComments($reader); } - /** - * Detect and consume block comments. - * - * @throws ScannerException - */ protected function consumeBlockComments(ReaderInterface $reader): bool { $nextChar = $reader->currentChar(); @@ -184,15 +171,13 @@ protected function consumeBlockComments(ReaderInterface $reader): bool return false; } - /** - * Detect and consume line comments. - */ protected function consumeLineComments(ReaderInterface $reader): bool { $nextChar = $reader->currentChar(); foreach ($this->context->getLineCommentDelimiters() as $delimiter) { if ($delimiter && $nextChar === $delimiter[0]) { - for ($i = 1; $i <= strlen($delimiter); ++$i) { + $delimiterLength = strlen($delimiter); + for ($i = 1; $i <= $delimiterLength; ++$i) { $reader->forward(); } @@ -218,9 +203,6 @@ protected function consumeLineComments(ReaderInterface $reader): bool return false; } - /** - * Detect and consume identifiers. - */ protected function consumeIdentifiers(ReaderInterface $reader): bool { $nextChar = $reader->currentChar(); @@ -239,9 +221,6 @@ protected function consumeIdentifiers(ReaderInterface $reader): bool return false; } - /** - * Detect and consume symbols. - */ protected function consumeSymbols(ReaderInterface $reader): bool { $found = false; diff --git a/src/PHPCR/Util/CND/Scanner/GenericToken.php b/src/PHPCR/Util/CND/Scanner/GenericToken.php index 9c52e98..9f88af8 100644 --- a/src/PHPCR/Util/CND/Scanner/GenericToken.php +++ b/src/PHPCR/Util/CND/Scanner/GenericToken.php @@ -36,6 +36,6 @@ public static function getTypeName(int $type): string public function __toString() { - return sprintf("TOKEN(%s, '%s', %s, %s)", self::getTypeName($this->getType()), trim($this->data), $this->line, $this->row); + return sprintf("TOKEN(%s, '%s', %s, %s)", self::getTypeName($this->getType()), trim($this->getData()), $this->getLine(), $this->getRow()); } } diff --git a/src/PHPCR/Util/CND/Scanner/Token.php b/src/PHPCR/Util/CND/Scanner/Token.php index 112e59e..1081328 100644 --- a/src/PHPCR/Util/CND/Scanner/Token.php +++ b/src/PHPCR/Util/CND/Scanner/Token.php @@ -15,35 +15,15 @@ */ class Token { - /** - * The type of token. - */ - public int $type; - - /** - * The token raw data. - */ - public string $data; - - /** - * The line where the token appears. - */ - protected int $line; - - /** - * The column where the token appears. - */ - protected int $row; - - /** - * Constructor. - */ - public function __construct(int $type = 0, string $data = '', int $line = 0, int $row = 0) - { - $this->type = $type; - $this->data = $data; - $this->line = $line; - $this->row = $row; + public function __construct( + private int $type = 0, + /** + * The token raw data. + */ + private string $data = '', + private int $line = 0, + private int $row = 0 + ) { } public function getData(): string diff --git a/src/PHPCR/Util/CND/Writer/CndWriter.php b/src/PHPCR/Util/CND/Writer/CndWriter.php index 33c0a89..20f8d5e 100644 --- a/src/PHPCR/Util/CND/Writer/CndWriter.php +++ b/src/PHPCR/Util/CND/Writer/CndWriter.php @@ -27,14 +27,14 @@ */ class CndWriter { - private NamespaceRegistryInterface $ns; - - /** @var array hashmap of prefix => namespace uri */ + /** + * @var array hashmap of prefix => namespace uri + */ private array $namespaces = []; - public function __construct(NamespaceRegistryInterface $ns) - { - $this->ns = $ns; + public function __construct( + private NamespaceRegistryInterface $ns + ) { } /** @@ -232,7 +232,7 @@ private function writeChildren(?array $children): string if ($child->isProtected()) { $attributes .= 'protected '; } - if (OnParentVersionAction::COPY != $child->getOnParentVersion()) { + if (OnParentVersionAction::COPY !== $child->getOnParentVersion()) { $attributes .= OnParentVersionAction::nameFromValue($child->getOnParentVersion()).' '; } if ($child->allowsSameNameSiblings()) { diff --git a/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php b/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php index ec98705..362df92 100644 --- a/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeRemoveCommand.php @@ -4,7 +4,6 @@ namespace PHPCR\Util\Console\Command; -use PHPCR\NodeInterface; use Symfony\Component\Console\Exception\InvalidArgumentException as CliInvalidArgumentException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -97,7 +96,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($onlyChildren) { $baseNode = $session->getNode($path, 0); - /** @var NodeInterface $childNode */ foreach ($baseNode->getNodes() as $childNode) { $childNodePath = $childNode->getPath(); $childNode->remove(); diff --git a/src/PHPCR/Util/Console/Command/NodeTouchCommand.php b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php index 3ff77f0..7d554af 100644 --- a/src/PHPCR/Util/Console/Command/NodeTouchCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php @@ -15,7 +15,7 @@ /** * Command to create a PHPCR node of a specified type from - * the command line.. + * the command line. * * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004 * @license http://opensource.org/licenses/MIT MIT License diff --git a/src/PHPCR/Util/Console/Helper/PhpcrHelper.php b/src/PHPCR/Util/Console/Helper/PhpcrHelper.php index 3af5473..f447df5 100644 --- a/src/PHPCR/Util/Console/Helper/PhpcrHelper.php +++ b/src/PHPCR/Util/Console/Helper/PhpcrHelper.php @@ -5,7 +5,6 @@ namespace PHPCR\Util\Console\Helper; use PHPCR\NodeInterface; -use PHPCR\PropertyInterface; use PHPCR\Query\QueryInterface; use PHPCR\SessionInterface; use Symfony\Component\Console\Helper\Helper; @@ -19,24 +18,13 @@ */ class PhpcrHelper extends Helper { - /** - * The session bound to this helper. - */ - protected SessionInterface $session; + private SessionInterface $session; - /** - * Constructor. - * - * @param SessionInterface $session the session to use in commands - */ public function __construct(SessionInterface $session) { $this->session = $session; } - /** - * Get the session. - */ public function getSession(): SessionInterface { return $this->session; @@ -124,7 +112,6 @@ public function processNode(OutputInterface $output, NodeInterface $node, array if ($operations['dump']) { $output->writeln('Node dump: '); - /** @var PropertyInterface $property */ foreach ($node->getProperties() as $property) { $value = $property->getValue(); if (!is_string($value)) { @@ -159,11 +146,9 @@ public function createQuery(string $language, string $sql): QueryInterface /** * Check if this is a supported query language. * - * @param string $language language name - * * @throws \Exception if the language is not supported */ - protected function validateQueryLanguage(string $language) + protected function validateQueryLanguage(string $language): string { $qm = $this->getSession()->getWorkspace()->getQueryManager(); $langs = $qm->getSupportedQueryLanguages(); diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php index d9b1d86..ecdd293 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperItemVisitor.php @@ -14,22 +14,14 @@ */ abstract class ConsoleDumperItemVisitor implements ItemVisitorInterface { - /** - * Target for printing information. - */ - protected OutputInterface $output; - /** * Current depth in the tree. */ protected int $level = 0; - /** - * Instantiate the console dumper visitor. - */ - public function __construct(OutputInterface $output) - { - $this->output = $output; + public function __construct( + protected OutputInterface $output + ) { } /** diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php index b788646..e1f8153 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperNodeVisitor.php @@ -26,9 +26,7 @@ class ConsoleDumperNodeVisitor extends ConsoleDumperItemVisitor protected bool $showFullPath = false; /** - * Instantiate the console dumper visitor. - * - * @param bool $identifiers whether to output the node UUID + * @param bool $identifiers whether to output the node UUIDs */ public function __construct(OutputInterface $output, bool $identifiers = false) { @@ -36,9 +34,6 @@ public function __construct(OutputInterface $output, bool $identifiers = false) $this->identifiers = $identifiers; } - /** - * If to show the full path or not. - */ public function setShowFullPath(bool $showFullPath): void { $this->showFullPath = $showFullPath; @@ -47,8 +42,6 @@ public function setShowFullPath(bool $showFullPath): void /** * Print information about the visited node. * - * @param ItemInterface $item the node to visit - * * @throws \Exception */ public function visit(ItemInterface $item): void diff --git a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php index 97f696d..cd07faa 100644 --- a/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php +++ b/src/PHPCR/Util/Console/Helper/TreeDumper/ConsoleDumperPropertyVisitor.php @@ -18,19 +18,12 @@ class ConsoleDumperPropertyVisitor extends ConsoleDumperItemVisitor { /** * Limit to cap lines at to avoid garbled output on long property values. - * - * @var int */ - protected mixed $maxLineLength; + protected int $maxLineLength; - /** - * @var string - */ - private mixed $refFormat; + private string $refFormat; /** - * Instantiate property visitor. - * * @param array $options */ public function __construct(OutputInterface $output, array $options = []) @@ -42,15 +35,13 @@ public function __construct(OutputInterface $output, array $options = []) parent::__construct($output); - $this->maxLineLength = $options['max_line_length']; - $this->refFormat = $options['ref_format']; + $this->maxLineLength = (int) $options['max_line_length']; + $this->refFormat = (string) $options['ref_format']; } /** * Print information about this property. * - * @param ItemInterface $item the property to visit - * * @throws \Exception */ public function visit(ItemInterface $item): void diff --git a/src/PHPCR/Util/NodeHelper.php b/src/PHPCR/Util/NodeHelper.php index 28abbd4..9792487 100644 --- a/src/PHPCR/Util/NodeHelper.php +++ b/src/PHPCR/Util/NodeHelper.php @@ -12,7 +12,6 @@ use PHPCR\NodeInterface; use PHPCR\NodeType\ConstraintViolationException; use PHPCR\PathNotFoundException; -use PHPCR\PropertyInterface; use PHPCR\RepositoryException; use PHPCR\SessionInterface; use PHPCR\Version\VersionException; @@ -35,7 +34,9 @@ private function __construct() } /** - * Create a node and it's parents, if necessary. Like mkdir -p. + * Create a node and it's parents, if necessary. + * + * Like mkdir -p. * * @param SessionInterface $session the PHPCR session to create the path * @param string $path full path, like /content/jobs/data @@ -87,14 +88,12 @@ public static function purgeWorkspace(SessionInterface $session): void { $root = $session->getRootNode(); - /** @var PropertyInterface $property */ foreach ($root->getProperties() as $property) { if (!self::isSystemItem($property)) { $property->remove(); } } - /** @var NodeInterface $node */ foreach ($root->getNodes() as $node) { if (!self::isSystemItem($node)) { $node->remove(); @@ -107,8 +106,6 @@ public static function purgeWorkspace(SessionInterface $session): void * usually want to hide and that should not be removed when purging the * repository. * - * @return bool true if $item is a system item, false otherwise - * * @throws RepositoryException */ public static function isSystemItem(ItemInterface $item): bool @@ -282,7 +279,7 @@ public static function calculateOrderBefore(array $old, array $new): array $newIndex = array_flip($new); foreach ($old as $key => $value) { - if (!isset($newIndex[$value])) { + if (!array_key_exists($value, $newIndex)) { unset($old[$key]); } } diff --git a/src/PHPCR/Util/PathHelper.php b/src/PHPCR/Util/PathHelper.php index e8fcbfc..ffa1464 100644 --- a/src/PHPCR/Util/PathHelper.php +++ b/src/PHPCR/Util/PathHelper.php @@ -124,13 +124,12 @@ public static function assertValidLocalName(string $name, bool $throw = true): b * @param bool $throw whether to throw an exception if validation fails or * just to return false * - * @return string The normalized path or false if $throw was false and the path invalid - * @return string The normalized path or false if $throw was false and the path invalid + * @return false|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 */ - public static function normalizePath(string $path, bool $destination = false, bool $throw = true): bool|string + public static function normalizePath(string $path, bool $destination = false, bool $throw = true): false|string { if ('' === $path) { return self::error('Path must not be of zero length', $throw); @@ -184,13 +183,13 @@ public static function normalizePath(string $path, bool $destination = false, bo * @param bool $throw whether to throw an exception if validation fails or * just to return false * - * @return string The normalized, absolute path or false if $throw was - * false and the path invalid + * @return false|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(string $path, string $context, bool $destination = false, bool $throw = true): bool|string + public static function absolutizePath(string $path, string $context, bool $destination = false, bool $throw = true): false|string { if ('' === $path) { return self::error('Path must not be of zero length', $throw); @@ -214,9 +213,9 @@ public static function absolutizePath(string $path, string $context, bool $desti * @param string $context The absolute path to an ancestor of $path * @param bool $throw whether to throw exceptions on invalid data * - * @return string The relative path from $context to $path + * @return false|string The relative path from $context to $path */ - public static function relativizePath(string $path, string $context, bool $throw = true): bool|string + public static function relativizePath(string $path, string $context, bool $throw = true): false|string { if (!str_starts_with($path, $context)) { return self::error("$path is not within $context", $throw); @@ -278,8 +277,6 @@ public static function getNodeName(string $path): string * * @param string $path a valid absolute path * - * @return string The localname - * * @throws RepositoryException */ public static function getLocalNodeName(string $path): string @@ -313,7 +310,7 @@ public static function getPathDepth(string $path): int * @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 * - * @return bool false + * @return false * * @throws RepositoryException */ diff --git a/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php b/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php index f4d8c38..f9444b7 100644 --- a/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php +++ b/src/PHPCR/Util/QOM/BaseQomToSqlQueryConverter.php @@ -17,9 +17,6 @@ abstract class BaseQomToSqlQueryConverter { protected BaseSqlGenerator $generator; - /** - * Instantiate the converter. - */ public function __construct(BaseSqlGenerator $generator) { $this->generator = $generator; diff --git a/src/PHPCR/Util/QOM/QueryBuilder.php b/src/PHPCR/Util/QOM/QueryBuilder.php index f7fa228..f29faa9 100644 --- a/src/PHPCR/Util/QOM/QueryBuilder.php +++ b/src/PHPCR/Util/QOM/QueryBuilder.php @@ -47,14 +47,14 @@ class QueryBuilder private int $maxResults = 0; /** - * @var OrderingInterface[] with the orderings that determine the order of the result + * @var OrderingInterface[] */ private array $orderings = []; private ?ConstraintInterface $constraint = null; /** - * @var ColumnInterface[] the columns to be selected + * @var ColumnInterface[] */ private array $columns = []; @@ -67,9 +67,6 @@ class QueryBuilder */ private array $params = []; - /** - * Initializes a new QueryBuilder. - */ public function __construct( private QueryObjectModelFactoryInterface $qomFactory ) { @@ -79,19 +76,18 @@ public function __construct( * Get a query builder instance from an existing query. * * @param string|QueryObjectModelInterface $statement the statement in the specified language - * @param string $language the query language * * @throws \InvalidArgumentException */ - public function setFromQuery(string|QueryObjectModelInterface $statement, string $language): static + public function setFromQuery(string|QueryObjectModelInterface $statement, string $queryLanguage): static { - if (QueryInterface::JCR_SQL2 === $language) { + if (QueryInterface::JCR_SQL2 === $queryLanguage) { $converter = new Sql2ToQomQueryConverter($this->qomFactory); $statement = $converter->parse($statement); } if (!$statement instanceof QueryObjectModelInterface) { - throw new \InvalidArgumentException("Language '$language' not supported"); + throw new \InvalidArgumentException("Language '$queryLanguage' not supported"); } $this->state = self::STATE_DIRTY; @@ -103,9 +99,6 @@ public function setFromQuery(string|QueryObjectModelInterface $statement, string return $this; } - /** - * Get the associated QOMFactory for this query builder. - */ public function getQOMFactory(): QueryObjectModelFactoryInterface { return $this->qomFactory; @@ -121,8 +114,6 @@ public function qomf(): QueryObjectModelFactoryInterface /** * sets the position of the first result to retrieve (the "offset"). - * - * @param int $firstResult the First result to return */ public function setFirstResult(int $firstResult): static { @@ -144,8 +135,6 @@ public function getFirstResult(): int /** * Sets the maximum number of results to retrieve (the "limit"). - * - * @param int $maxResults the maximum number of results to retrieve */ public function setMaxResults(int $maxResults): static { @@ -164,9 +153,7 @@ public function getMaxResults(): int } /** - * Gets the array of orderings. - * - * @return OrderingInterface[] orderings to apply + * @return OrderingInterface[] */ public function getOrderings(): array { @@ -288,9 +275,7 @@ public function orWhere(ConstraintInterface $constraint): static } /** - * Returns the columns to be selected. - * - * @return ColumnInterface[] The columns to be selected + * @return ColumnInterface[] */ public function getColumns(): array { @@ -298,9 +283,7 @@ public function getColumns(): array } /** - * Sets the columns to be selected. - * - * @param ColumnInterface[] $columns The columns to be selected + * @param ColumnInterface[] $columns */ public function setColumns(array $columns): static { @@ -348,7 +331,7 @@ public function from(SourceInterface $source): static /** * Gets the default Selector. * - * @return SourceInterface the default selector + * @return SourceInterface|null the default selector */ public function getSource(): ?SourceInterface { @@ -455,13 +438,10 @@ public function execute(): QueryResultInterface /** * Sets a query parameter for the query being constructed. - * - * @param string $key the parameter name - * @param mixed $value the parameter value */ - public function setParameter(string $key, mixed $value): static + public function setParameter(string $parameterName, mixed $parameterValue): static { - $this->params[$key] = $value; + $this->params[$parameterName] = $parameterValue; return $this; } @@ -469,9 +449,9 @@ public function setParameter(string $key, mixed $value): static /** * Gets a (previously set) query parameter of the query being constructed. */ - public function getParameter(string $key): mixed + public function getParameter(string $parameterName): mixed { - return $this->params[$key] ?? null; + return $this->params[$parameterName] ?? null; } /** @@ -487,9 +467,7 @@ public function setParameters(array $params): static } /** - * Gets all defined query parameters for the query being constructed. - * - * @return array + * @return array Map of parameter name => parameter value */ public function getParameters(): array { diff --git a/src/PHPCR/Util/QOM/Sql1Generator.php b/src/PHPCR/Util/QOM/Sql1Generator.php index 3f637a9..bcd7b93 100644 --- a/src/PHPCR/Util/QOM/Sql1Generator.php +++ b/src/PHPCR/Util/QOM/Sql1Generator.php @@ -68,8 +68,8 @@ public function evalDescendantNode(string $path, string $selectorName = null): s * PropertyExistence ::= * 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 + * @param string|null $selectorName declared to simplifiy interface - as there + * are no joins in SQL1 there is no need for a selector */ public function evalPropertyExistence(?string $selectorName, string $propertyName): string { diff --git a/src/PHPCR/Util/QOM/Sql2Scanner.php b/src/PHPCR/Util/QOM/Sql2Scanner.php index 1f83f7d..0ec2a83 100644 --- a/src/PHPCR/Util/QOM/Sql2Scanner.php +++ b/src/PHPCR/Util/QOM/Sql2Scanner.php @@ -31,9 +31,6 @@ class Sql2Scanner */ protected int $curpos = 0; - /** - * Construct a scanner with the given SQL2 statement. - */ public function __construct(string $sql2) { $this->sql2 = $sql2; diff --git a/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php b/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php index bde4417..880a0f9 100644 --- a/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php +++ b/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php @@ -6,10 +6,12 @@ use PHPCR\PropertyType; use PHPCR\Query\InvalidQueryException; +use PHPCR\Query\QOM\ChildNodeInterface; use PHPCR\Query\QOM\ChildNodeJoinConditionInterface; use PHPCR\Query\QOM\ColumnInterface; use PHPCR\Query\QOM\ComparisonInterface; use PHPCR\Query\QOM\ConstraintInterface; +use PHPCR\Query\QOM\DescendantNodeInterface; use PHPCR\Query\QOM\DescendantNodeJoinConditionInterface; use PHPCR\Query\QOM\DynamicOperandInterface; use PHPCR\Query\QOM\EquiJoinConditionInterface; @@ -22,6 +24,7 @@ use PHPCR\Query\QOM\QueryObjectModelConstantsInterface as Constants; use PHPCR\Query\QOM\QueryObjectModelFactoryInterface; use PHPCR\Query\QOM\QueryObjectModelInterface; +use PHPCR\Query\QOM\SameNodeInterface; use PHPCR\Query\QOM\SameNodeJoinConditionInterface; use PHPCR\Query\QOM\SelectorInterface; use PHPCR\Query\QOM\SourceInterface; @@ -36,16 +39,8 @@ */ class Sql2ToQomQueryConverter { - /** - * The factory to create QOM objects. - */ protected QueryObjectModelFactoryInterface $factory; - /** - * Scanner to parse SQL2. - * - * @var Sql2Scanner; - */ protected Sql2Scanner $scanner; /** @@ -64,8 +59,6 @@ class Sql2ToQomQueryConverter private ValueConverter $valueConverter; /** - * Instantiate a converter. - * * @param ValueConverter|null $valueConverter to override default converter */ public function __construct(QueryObjectModelFactoryInterface $factory, ValueConverter $valueConverter = null) @@ -128,8 +121,6 @@ public function parse($sql2): QueryObjectModelInterface /** * 6.7.2. Source * Parse an SQL2 source definition and return the corresponding QOM Source. - * - * @return SourceInterface */ protected function parseSource(): JoinInterface|SourceInterface|SelectorInterface { @@ -225,10 +216,8 @@ protected function parseJoinType(): string /** * 6.7.7. JoinCondition * Parse an SQL2 join condition and return a JoinConditionInterface. - * - * @return JoinConditionInterface */ - protected function parseJoinCondition(): SameNodeJoinConditionInterface|EquiJoinConditionInterface|DescendantNodeJoinConditionInterface|ChildNodeJoinConditionInterface|JoinConditionInterface + protected function parseJoinCondition(): JoinConditionInterface { $this->scanner->expectToken('ON'); @@ -324,7 +313,7 @@ protected function parseDescendantNodeJoinCondition(): DescendantNodeJoinConditi * * @throws \Exception */ - protected function parseConstraint(ConstraintInterface $lhs = null, int $minprec = 0): FullTextSearchInterface|ComparisonInterface|NotInterface|ConstraintInterface|null + protected function parseConstraint(ConstraintInterface $lhs = null, int $minprec = 0): ConstraintInterface|null { if (null === $lhs) { $lhs = $this->parsePrimaryConstraint(); @@ -370,10 +359,8 @@ protected function parseConstraint(ConstraintInterface $lhs = null, int $minprec /** * 6.7.12 Constraint. - * - * @return ConstraintInterface */ - protected function parsePrimaryConstraint() + protected function parsePrimaryConstraint(): ConstraintInterface { $constraint = null; $token = $this->scanner->lookupNextToken(); @@ -519,7 +506,7 @@ protected function parseFullTextSearch(): FullTextSearchInterface /** * 6.7.20 SameNode. */ - protected function parseSameNode() + protected function parseSameNode(): SameNodeInterface { $this->scanner->expectTokens(['ISSAMENODE', '(']); if ($this->scanner->tokenIs($this->scanner->lookupNextToken(1), ',')) { @@ -538,7 +525,7 @@ protected function parseSameNode() /** * 6.7.21 ChildNode. */ - protected function parseChildNode(): \PHPCR\Query\QOM\ChildNodeInterface + protected function parseChildNode(): ChildNodeInterface { $this->scanner->expectTokens(['ISCHILDNODE', '(']); if ($this->scanner->tokenIs($this->scanner->lookupNextToken(1), ',')) { @@ -557,7 +544,7 @@ protected function parseChildNode(): \PHPCR\Query\QOM\ChildNodeInterface /** * 6.7.22 DescendantNode. */ - protected function parseDescendantNode(): \PHPCR\Query\QOM\DescendantNodeInterface + protected function parseDescendantNode(): DescendantNodeInterface { $this->scanner->expectTokens(['ISDESCENDANTNODE', '(']); if ($this->scanner->tokenIs($this->scanner->lookupNextToken(1), ',')) { @@ -583,7 +570,7 @@ protected function parseDescendantNode(): \PHPCR\Query\QOM\DescendantNodeInterfa protected function parsePath() { $path = $this->parseLiteralValue(); - if ('[' === substr($path, 0, 1) && ']' === substr($path, -1)) { + if (str_starts_with($path, '[') && str_ends_with($path, ']')) { $path = substr($path, 1, -1); } @@ -598,7 +585,7 @@ protected function parsePath() protected function parseStaticOperand(): StaticOperandInterface { $token = $this->scanner->lookupNextToken(); - if ('$' === substr($token, 0, 1)) { + if (str_starts_with($token, '$')) { return $this->factory->bindVariable(substr($this->scanner->fetchNextToken(), 1)); } @@ -614,8 +601,6 @@ protected function parseStaticOperand(): StaticOperandInterface * 6.7.32 LowerCase * 6.7.33 UpperCase * Parse an SQL2 dynamic operand. - * - * @return DynamicOperandInterface */ protected function parseDynamicOperand(): DynamicOperandInterface|PropertyValueInterface { @@ -893,8 +878,8 @@ private function fetchTokenWithoutBrackets(): string * * @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 + * @return string[] with selectorName and propertyName. If no selectorName is + * specified, defaults to $this->defaultSelectorName */ private function parseIdentifier(bool $checkSelector = true): array { @@ -939,14 +924,12 @@ protected function updateImplicitSelectorName(string $selectorName): void /** * Ensure that the parsedName is a valid selector, or return the implicit - * selector if its non-ambigous. - * - * @return string the selector to use + * selector if its non-ambiguous. * * @throws InvalidQueryException if there was no explicit selector and * there is more than one selector available */ - protected function ensureSelectorName(?string $parsedName): array|string|null + protected function ensureSelectorName(?string $parsedName): string|null { if (null !== $parsedName) { if ((is_array($this->implicitSelectorName) && !isset($this->implicitSelectorName[$parsedName])) diff --git a/src/PHPCR/Util/TraversingItemVisitor.php b/src/PHPCR/Util/TraversingItemVisitor.php index 1ee1ced..4707e96 100644 --- a/src/PHPCR/Util/TraversingItemVisitor.php +++ b/src/PHPCR/Util/TraversingItemVisitor.php @@ -61,8 +61,6 @@ abstract class TraversingItemVisitor implements ItemVisitorInterface protected int $currentDepth; /** - * Constructs a new instance of this class. - * * @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) @@ -70,8 +68,6 @@ abstract class TraversingItemVisitor implements ItemVisitorInterface * 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) - * - * @api */ public function __construct(bool $breadthFirst = false, int $maxDepth = -1) { diff --git a/src/PHPCR/Util/TreeWalker.php b/src/PHPCR/Util/TreeWalker.php index 0ebe6f0..723b54b 100644 --- a/src/PHPCR/Util/TreeWalker.php +++ b/src/PHPCR/Util/TreeWalker.php @@ -17,14 +17,8 @@ */ class TreeWalker { - /** - * Visitor for nodes. - */ protected ItemVisitorInterface $nodeVisitor; - /** - * Visitor for properties. - */ protected ?ItemVisitorInterface $propertyVisitor; /** @@ -42,8 +36,6 @@ class TreeWalker protected array $propertyFilters = []; /** - * Instantiate a tree walker. - * * @param ItemVisitorInterface $nodeVisitor The visitor for the nodes * @param ItemVisitorInterface|null $propertyVisitor The visitor for the nodes properties */ @@ -53,9 +45,6 @@ public function __construct(ItemVisitorInterface $nodeVisitor, ItemVisitorInterf $this->propertyVisitor = $propertyVisitor; } - /** - * Add a filter to select the nodes that will be traversed. - */ public function addNodeFilter(TreeWalkerFilterInterface $filter): void { if (!in_array($filter, $this->nodeFilters, true)) { @@ -63,12 +52,9 @@ public function addNodeFilter(TreeWalkerFilterInterface $filter): void } } - /** - * Add a filter to select the properties that will be traversed. - */ public function addPropertyFilter(TreeWalkerFilterInterface $filter): void { - if (!in_array($filter, $this->propertyFilters)) { + if (!in_array($filter, $this->propertyFilters, true)) { $this->propertyFilters[] = $filter; } } @@ -102,10 +88,8 @@ protected function mustVisitProperty(PropertyInterface $property): bool } /** - * Traverse a node. - * * @param int $recurse Max recursion level - * @param int $level Recursion level + * @param int $level Current recursion level */ public function traverse(NodeInterface $node, int $recurse = -1, int $level = 0): void { diff --git a/src/PHPCR/Util/UUIDHelper.php b/src/PHPCR/Util/UUIDHelper.php index 6b5f5ec..f9a7695 100644 --- a/src/PHPCR/Util/UUIDHelper.php +++ b/src/PHPCR/Util/UUIDHelper.php @@ -18,8 +18,6 @@ class UUIDHelper * Checks if the string could be a UUID. * * @param string $id Possible uuid - * - * @return bool true if the test was passed, else false */ public static function isUUID(string $id): bool { diff --git a/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php b/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php index 84982b5..7936038 100644 --- a/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php +++ b/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php @@ -14,7 +14,10 @@ class GenericScannerTest extends TestCase { - protected $expectedTokens = [ + /** + * @var array + */ + private array $expectedTokens = [ // [Token::TK_SYMBOL, '<'], [Token::TK_SYMBOL, '?'], @@ -104,7 +107,10 @@ class GenericScannerTest extends TestCase [Token::TK_NEWLINE, ''], ]; - protected $expectedTokensNoEmptyToken; + /** + * @var Token[] + */ + protected array $expectedTokensNoEmptyToken; public function setUp(): void { diff --git a/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php b/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php index 08b7673..79cf660 100644 --- a/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php +++ b/tests/PHPCR/Tests/Util/CND/Scanner/TokenTest.php @@ -21,8 +21,8 @@ public function setUp(): void public function testConstruct(): void { - $this->assertSame(123, $this->token->type); - $this->assertSame('foobar', $this->token->data); + $this->assertSame(123, $this->token->getType()); + $this->assertSame('foobar', $this->token->getData()); } public function testGetData(): void