@@ -22,20 +22,20 @@ |
||
22 | 22 | * @return string |
23 | 23 | */ |
24 | 24 | public function newGuid() { |
25 | - if ( function_exists( 'com_create_guid' ) ) { |
|
26 | - return trim( com_create_guid(), '{}' ); |
|
25 | + if (function_exists('com_create_guid')) { |
|
26 | + return trim(com_create_guid(), '{}'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | return sprintf( |
30 | 30 | '%04X%04X-%04X-%04X-%04X-%04X%04X%04X', |
31 | - mt_rand( 0, 65535 ), |
|
32 | - mt_rand( 0, 65535 ), |
|
33 | - mt_rand( 0, 65535 ), |
|
34 | - mt_rand( 16384, 20479 ), |
|
35 | - mt_rand( 32768, 49151 ), |
|
36 | - mt_rand( 0, 65535 ), |
|
37 | - mt_rand( 0, 65535 ), |
|
38 | - mt_rand( 0, 65535 ) |
|
31 | + mt_rand(0, 65535), |
|
32 | + mt_rand(0, 65535), |
|
33 | + mt_rand(0, 65535), |
|
34 | + mt_rand(16384, 20479), |
|
35 | + mt_rand(32768, 49151), |
|
36 | + mt_rand(0, 65535), |
|
37 | + mt_rand(0, 65535), |
|
38 | + mt_rand(0, 65535) |
|
39 | 39 | ); |
40 | 40 | } |
41 | 41 |
@@ -21,8 +21,8 @@ |
||
21 | 21 | * @return StatementList[] An associative array, mapping the default group identifier |
22 | 22 | * "statements" to the unmodified StatementList object. |
23 | 23 | */ |
24 | - public function groupStatements( StatementList $statements ) { |
|
25 | - return [ 'statements' => $statements ]; |
|
24 | + public function groupStatements(StatementList $statements) { |
|
25 | + return ['statements' => $statements]; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | } |
@@ -20,6 +20,6 @@ |
||
20 | 20 | * included. The array keys act as identifiers for each group, and can be used as (parts of) |
21 | 21 | * message keys. |
22 | 22 | */ |
23 | - public function groupStatements( StatementList $statements ); |
|
23 | + public function groupStatements(StatementList $statements); |
|
24 | 24 | |
25 | 25 | } |
@@ -18,18 +18,18 @@ |
||
18 | 18 | * @return StatementList[] An associative array, mapping property id serializations to |
19 | 19 | * StatementList objects. |
20 | 20 | */ |
21 | - public function groupStatements( StatementList $statements ) { |
|
21 | + public function groupStatements(StatementList $statements) { |
|
22 | 22 | /** @var StatementList[] $groups */ |
23 | 23 | $groups = []; |
24 | 24 | |
25 | - foreach ( $statements->toArray() as $statement ) { |
|
25 | + foreach ($statements->toArray() as $statement) { |
|
26 | 26 | $id = $statement->getPropertyId()->getSerialization(); |
27 | 27 | |
28 | - if ( !isset( $groups[$id] ) ) { |
|
28 | + if (!isset($groups[$id])) { |
|
29 | 29 | $groups[$id] = new StatementList(); |
30 | 30 | } |
31 | 31 | |
32 | - $groups[$id]->addStatement( $statement ); |
|
32 | + $groups[$id]->addStatement($statement); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | return $groups; |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @throws InvalidArgumentException |
40 | 40 | */ |
41 | - public function __construct( array $filters ) { |
|
42 | - foreach ( $filters as $key => $filter ) { |
|
43 | - if ( $filter instanceof StatementFilter ) { |
|
41 | + public function __construct(array $filters) { |
|
42 | + foreach ($filters as $key => $filter) { |
|
43 | + if ($filter instanceof StatementFilter) { |
|
44 | 44 | $this->filters[$key] = $filter; |
45 | - } elseif ( $filter === null ) { |
|
46 | - $this->setDefaultGroupIdentifier( $key ); |
|
45 | + } elseif ($filter === null) { |
|
46 | + $this->setDefaultGroupIdentifier($key); |
|
47 | 47 | } else { |
48 | - throw new InvalidArgumentException( '$filter must be a StatementFilter or null' ); |
|
48 | + throw new InvalidArgumentException('$filter must be a StatementFilter or null'); |
|
49 | 49 | } |
50 | 50 | |
51 | - $this->setGroupIdentifier( $key ); |
|
51 | + $this->setGroupIdentifier($key); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $this->initializeDefaultGroup(); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @param string $key |
59 | 59 | */ |
60 | - private function setGroupIdentifier( $key ) { |
|
60 | + private function setGroupIdentifier($key) { |
|
61 | 61 | $this->groupIdentifiers[$key] = $key; |
62 | 62 | } |
63 | 63 | |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @throws InvalidArgumentException |
68 | 68 | */ |
69 | - private function setDefaultGroupIdentifier( $key ) { |
|
70 | - if ( $this->defaultGroupIdentifier !== null ) { |
|
71 | - throw new InvalidArgumentException( 'You must only define one default group' ); |
|
69 | + private function setDefaultGroupIdentifier($key) { |
|
70 | + if ($this->defaultGroupIdentifier !== null) { |
|
71 | + throw new InvalidArgumentException('You must only define one default group'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $this->defaultGroupIdentifier = $key; |
75 | 75 | } |
76 | 76 | |
77 | 77 | private function initializeDefaultGroup() { |
78 | - if ( $this->defaultGroupIdentifier === null ) { |
|
78 | + if ($this->defaultGroupIdentifier === null) { |
|
79 | 79 | $this->defaultGroupIdentifier = 'statements'; |
80 | - $this->setGroupIdentifier( $this->defaultGroupIdentifier ); |
|
80 | + $this->setGroupIdentifier($this->defaultGroupIdentifier); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | * StatementList objects. All identifiers given in the constructor are guaranteed to be in the |
89 | 89 | * result. |
90 | 90 | */ |
91 | - public function groupStatements( StatementList $statements ) { |
|
91 | + public function groupStatements(StatementList $statements) { |
|
92 | 92 | $groups = $this->getEmptyGroups(); |
93 | 93 | |
94 | - foreach ( $statements->toArray() as $statement ) { |
|
95 | - $key = $this->getKey( $statement ); |
|
96 | - $groups[$key]->addStatement( $statement ); |
|
94 | + foreach ($statements->toArray() as $statement) { |
|
95 | + $key = $this->getKey($statement); |
|
96 | + $groups[$key]->addStatement($statement); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | return $groups; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | private function getEmptyGroups() { |
106 | 106 | $groups = []; |
107 | 107 | |
108 | - foreach ( $this->groupIdentifiers as $key ) { |
|
108 | + foreach ($this->groupIdentifiers as $key) { |
|
109 | 109 | $groups[$key] = new StatementList(); |
110 | 110 | } |
111 | 111 | |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return string Statement group identifier |
119 | 119 | */ |
120 | - private function getKey( Statement $statement ) { |
|
121 | - foreach ( $this->filters as $key => $filter ) { |
|
122 | - if ( $filter->statementMatches( $statement ) ) { |
|
120 | + private function getKey(Statement $statement) { |
|
121 | + foreach ($this->filters as $key => $filter) { |
|
122 | + if ($filter->statementMatches($statement)) { |
|
123 | 123 | return $key; |
124 | 124 | } |
125 | 125 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare( strict_types=1 ); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Wikibase\DataModel\Services\Statement; |
4 | 4 | |
@@ -21,22 +21,22 @@ discard block |
||
21 | 21 | |
22 | 22 | private EntityIdParser $entityIdParser; |
23 | 23 | |
24 | - public function __construct( EntityIdParser $entityIdParser ) { |
|
24 | + public function __construct(EntityIdParser $entityIdParser) { |
|
25 | 25 | $this->entityIdParser = $entityIdParser; |
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @throws StatementGuidParsingException |
30 | 30 | */ |
31 | - public function parse( string $serialization ): StatementGuid { |
|
32 | - $keyParts = explode( StatementGuid::SEPARATOR, $serialization, 2 ); |
|
33 | - if ( count( $keyParts ) !== 2 ) { |
|
34 | - throw new StatementGuidParsingException( '$serialization does not have the correct number of parts' ); |
|
31 | + public function parse(string $serialization): StatementGuid { |
|
32 | + $keyParts = explode(StatementGuid::SEPARATOR, $serialization, 2); |
|
33 | + if (count($keyParts) !== 2) { |
|
34 | + throw new StatementGuidParsingException('$serialization does not have the correct number of parts'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | try { |
38 | - return new StatementGuid( $this->entityIdParser->parse( $keyParts[0] ), $keyParts[1], $serialization ); |
|
39 | - } catch ( EntityIdParsingException $ex ) { |
|
38 | + return new StatementGuid($this->entityIdParser->parse($keyParts[0]), $keyParts[1], $serialization); |
|
39 | + } catch (EntityIdParsingException $ex) { |
|
40 | 40 | throw new StatementGuidParsingException( |
41 | 41 | '$serialization contains invalid EntityId: ' |
42 | 42 | . $ex->getMessage() |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function statementMatches( Statement $statement ) { |
|
32 | + public function statementMatches(Statement $statement) { |
|
33 | 33 | return true; |
34 | 34 | } |
35 | 35 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @param string[]|string $propertyIds One or more property id serializations. |
31 | 31 | */ |
32 | - public function __construct( $propertyIds ) { |
|
32 | + public function __construct($propertyIds) { |
|
33 | 33 | $this->propertyIds = (array)$propertyIds; |
34 | 34 | } |
35 | 35 | |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function statementMatches( Statement $statement ) { |
|
43 | + public function statementMatches(Statement $statement) { |
|
44 | 44 | $id = $statement->getPropertyId()->getSerialization(); |
45 | - return in_array( $id, $this->propertyIds ); |
|
45 | + return in_array($id, $this->propertyIds); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |
@@ -33,12 +33,12 @@ |
||
33 | 33 | * |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - public function newGuid( EntityId $entityId ) { |
|
36 | + public function newGuid(EntityId $entityId) { |
|
37 | 37 | return $entityId->getSerialization() . StatementGuid::SEPARATOR . $this->baseGenerator->newGuid(); |
38 | 38 | } |
39 | 39 | |
40 | - public function newStatementId( EntityId $entityId ): StatementGuid { |
|
41 | - return new StatementGuid( $entityId, $this->baseGenerator->newGuid() ); |
|
40 | + public function newStatementId(EntityId $entityId): StatementGuid { |
|
41 | + return new StatementGuid($entityId, $this->baseGenerator->newGuid()); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | } |