Skip to content

Commit 1ec8331

Browse files
committed
adjust phpspec tests to correct typing
1 parent 4666529 commit 1ec8331

File tree

5 files changed

+40
-50
lines changed

5 files changed

+40
-50
lines changed

Diff for: spec/PHPCR/Shell/Query/UpdateParserSpec.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use PHPCR\Query\QOM\PropertyValueInterface;
2020
use PHPCR\Query\QOM\QueryObjectModelConstantsInterface;
2121
use PHPCR\Query\QOM\QueryObjectModelFactoryInterface;
22-
use PHPCR\Query\QOM\SourceInterface;
22+
use PHPCR\Query\QOM\SelectorInterface;
2323
use PHPCR\Query\QueryInterface;
2424
use PhpSpec\ObjectBehavior;
2525

@@ -42,17 +42,17 @@ public function it_should_provide_a_qom_object_for_selecting(
4242
QueryObjectModelFactoryInterface $qomf,
4343
ChildNodeJoinConditionInterface $joinCondition,
4444
JoinInterface $join,
45-
SourceInterface $parentSource,
46-
SourceInterface $childSource,
45+
SelectorInterface $parentSelector,
46+
SelectorInterface $childSelector,
4747
PropertyValueInterface $childValue,
4848
LiteralInterface $literalValue,
4949
ComparisonInterface $comparison,
5050
QueryInterface $query
5151
) {
52-
$qomf->selector('parent', 'mgnl:page')->willReturn($parentSource);
53-
$qomf->selector('child', 'mgnl:metaData')->willReturn($childSource);
52+
$qomf->selector('parent', 'mgnl:page')->willReturn($parentSelector);
53+
$qomf->selector('child', 'mgnl:metaData')->willReturn($childSelector);
5454
$qomf->childNodeJoinCondition('child', 'parent')->willReturn($joinCondition);
55-
$qomf->join($parentSource, $childSource, QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER, $joinCondition)->willReturn($join);
55+
$qomf->join($parentSelector, $childSelector, QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER, $joinCondition)->willReturn($join);
5656
$qomf->propertyValue('child', 'mgnl:template')->willReturn($childValue);
5757
$qomf->literal('standard-templating-kit:stkNews')->willReturn($literalValue);
5858
$qomf->comparison($childValue, QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO, $literalValue)->willReturn($comparison);
@@ -68,9 +68,9 @@ public function it_should_provide_a_qom_object_for_selecting(
6868
WHERE
6969
child.[mgnl:template] = 'standard-templating-kit:stkNews'
7070
EOT;
71-
$res = $this->parse($sql);
71+
$res = $this->parseUpdate($sql);
7272

73-
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
73+
$res->offsetGet(0)->shouldHaveType(QueryInterface::class);
7474
$res->offsetGet(1)->shouldReturn([
7575
[
7676
'selector' => 'parent',
@@ -87,7 +87,7 @@ public function it_should_provide_a_qom_object_for_selecting(
8787

8888
public function it_should_parse_functions(
8989
QueryObjectModelFactoryInterface $qomf,
90-
SourceInterface $source,
90+
SelectorInterface $source,
9191
QueryInterface $query
9292
) {
9393
$qomf->selector('a', 'dtl:article')->willReturn($source);
@@ -96,14 +96,14 @@ public function it_should_parse_functions(
9696
$sql = <<<'EOT'
9797
UPDATE [dtl:article] AS a SET a.tags = array_replace(a.tags, 'asd', 'dsa')
9898
EOT;
99-
$res = $this->parse($sql);
99+
$res = $this->parseUpdate($sql);
100100

101101
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
102102
}
103103

104104
public function it_should_parse_apply(
105105
QueryObjectModelFactoryInterface $qomf,
106-
SourceInterface $source,
106+
SelectorInterface $source,
107107
QueryInterface $query
108108
) {
109109
$qomf->selector('a', 'dtl:article')->willReturn($source);
@@ -112,7 +112,7 @@ public function it_should_parse_apply(
112112
$sql = <<<'EOT'
113113
UPDATE [dtl:article] AS a APPLY nodetype_add('nt:barbar')
114114
EOT;
115-
$res = $this->parse($sql);
115+
$res = $this->parseUpdate($sql);
116116

117117
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
118118
}

Diff for: src/PHPCR/Shell/Console/Application/ShellApplication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function add(Command $command): ?Command
285285
if ($command instanceof BasePhpcrCommand
286286
&& ($this->showUnsupported || $command->isSupported())
287287
) {
288-
return parent::add($command);
288+
return parent::add($command);
289289
}
290290

291291
return parent::add($command);

Diff for: src/PHPCR/Shell/Console/Command/Phpcr/QueryUpdateCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
7575
$qm = $session->getWorkspace()->getQueryManager();
7676

7777
$updateParser = new UpdateParser($qm->getQOMFactory());
78-
$res = $updateParser->parse($sql);
78+
$res = $updateParser->parseUpdate($sql);
7979
$query = $res->offsetGet(0);
8080
$updates = $res->offsetGet(1);
8181
$applies = $res->offsetGet(3);

Diff for: src/PHPCR/Shell/Console/Input/StringInput.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public function getRawCommand()
6363
return $this->rawCommand;
6464
}
6565

66-
public function validate()
66+
public function validate(): void
6767
{
6868
if (false === $this->isQuery()) {
69-
return parent::validate();
69+
parent::validate();
7070
}
7171
}
7272

@@ -75,10 +75,10 @@ public function validate()
7575
*
7676
* {@inheritdoc}
7777
*/
78-
protected function parse()
78+
protected function parse(): void
7979
{
8080
if (false === $this->isQuery()) {
81-
return parent::parse();
81+
parent::parse();
8282
}
8383
}
8484

@@ -87,7 +87,7 @@ protected function parse()
8787
* allowed by the default StringInput and we require
8888
* it for the "alias" feature.
8989
*/
90-
protected function setTokens(array $tokens)
90+
protected function setTokens(array $tokens): void
9191
{
9292
$this->tokens = $tokens;
9393
parent::setTokens($tokens);

Diff for: src/PHPCR/Shell/Query/UpdateParser.php

+21-31
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
namespace PHPCR\Shell\Query;
1414

1515
use PHPCR\Query\InvalidQueryException;
16+
use PHPCR\Query\QOM\ConstraintInterface;
17+
use PHPCR\Query\QOM\QueryObjectModelInterface;
1618
use PHPCR\Query\QOM\SourceInterface;
1719
use PHPCR\Util\QOM\Sql2Scanner;
1820
use PHPCR\Util\QOM\Sql2ToQomQueryConverter;
@@ -27,27 +29,21 @@
2729
*/
2830
class UpdateParser extends Sql2ToQomQueryConverter
2931
{
30-
public function parse($sql2)
31-
{
32-
$this->scanner = new Sql2Scanner($sql2);
33-
$this->sql2 = $sql2;
34-
35-
return $this->doParse($sql2);
36-
}
37-
3832
/**
3933
* Parse an "SQL2" UPDATE statement and construct a query builder
4034
* for selecting the rows and build a field => value mapping for the
4135
* update.
4236
*
4337
* @param string $sql2
4438
*
45-
* @return array($query, $updates)
39+
* @return \ArrayObject{1: QueryObjectModelInterface, 2: array, 3: ?ConstraintInterface, 4: array}
4640
*/
47-
private function doParse($sql2)
41+
public function parseUpdate($sql2): \ArrayObject
4842
{
49-
$this->implicitSelectorName = null;
43+
$this->scanner = new Sql2Scanner($sql2);
5044
$this->sql2 = $sql2;
45+
46+
$this->implicitSelectorName = null;
5147
$source = null;
5248
$constraint = null;
5349
$updates = [];
@@ -82,25 +78,17 @@ private function doParse($sql2)
8278

8379
$query = $this->factory->createQuery($source, $constraint);
8480

85-
$res = new \ArrayObject([$query, $updates, $constraint, $applies]);
86-
87-
return $res;
81+
return new \ArrayObject([$query, $updates, $constraint, $applies]);
8882
}
8983

9084
/**
9185
* Parse the SET section of the query, returning
9286
* an array containing the property names (<selectorName.propertyName)
9387
* as keys and an array.
9488
*
95-
* array(
96-
* 'selector' => <selector>,
97-
* 'name' => <name>,
98-
* '<value>' => <property value>,
99-
* )
100-
*
101-
* @return array
89+
* @return array{'selector': string, 'name': string, 'value': mixed}
10290
*/
103-
private function parseUpdates()
91+
private function parseUpdates(): array
10492
{
10593
$updates = [];
10694

@@ -132,9 +120,9 @@ private function parseUpdates()
132120

133121
$next = $this->scanner->lookupNextToken();
134122

135-
if ($next == ',') {
123+
if (',' === $next) {
136124
$next = $this->scanner->fetchNextToken();
137-
} elseif (strtolower($next) == 'where' || !$next) {
125+
} elseif (strtolower($next) === 'where' || !$next) {
138126
break;
139127
}
140128
}
@@ -144,11 +132,13 @@ private function parseUpdates()
144132

145133
private function isLiteral($token)
146134
{
147-
if (substr($token, 0, 1) === '\'') {
135+
if (str_starts_with($token, '\'')) {
148136
return true;
149-
} elseif (is_numeric($token)) {
137+
}
138+
if (is_numeric($token)) {
150139
return true;
151-
} elseif (substr($token, 0, 1) === '"') {
140+
}
141+
if (str_starts_with($token, '"')) {
152142
return true;
153143
}
154144

@@ -159,7 +149,7 @@ private function parseOperand()
159149
{
160150
$token = strtoupper($this->scanner->lookupNextToken());
161151

162-
if ($this->scanner->lookupNextToken(1) == '(') {
152+
if ($this->scanner->lookupNextToken(1) === '(') {
163153
$functionData = $this->parseFunction();
164154

165155
return new FunctionOperand($functionData[0], $functionData[1]);
@@ -187,17 +177,17 @@ private function parseApply()
187177
while (true) {
188178
$token = strtoupper($this->scanner->lookupNextToken());
189179

190-
if ($this->scanner->lookupNextToken(1) == '(') {
180+
if ($this->scanner->lookupNextToken(1) === '(') {
191181
$functionData = $this->parseFunction();
192182

193183
$functions[] = new FunctionOperand($functionData[0], $functionData[1]);
194184
}
195185

196186
$next = $this->scanner->lookupNextToken();
197187

198-
if ($next == ',') {
188+
if (',' === $next) {
199189
$next = $this->scanner->fetchNextToken();
200-
} elseif (strtolower($next) == 'where' || !$next) {
190+
} elseif (strtolower($next) === 'where' || !$next) {
201191
break;
202192
}
203193
}

0 commit comments

Comments
 (0)