File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,4 +103,21 @@ public static function newFromNumber( $numericId ) {
103103 return new self ( 'Q ' . $ numericId );
104104 }
105105
106+ /**
107+ * CAUTION: Use the full string serialization whenever you can and avoid using numeric IDs.
108+ *
109+ * @param string $repositoryName
110+ * @param int|float|string $numericId
111+ *
112+ * @return self
113+ * @throws InvalidArgumentException
114+ */
115+ public static function newFromRepositoryAndNumber ( $ repositoryName , $ numericId ) {
116+ if ( !is_numeric ( $ numericId ) ) {
117+ throw new InvalidArgumentException ( '$numericId must be numeric ' );
118+ }
119+
120+ return new self ( self ::joinSerialization ( [ $ repositoryName , '' , 'Q ' . $ numericId ] ) );
121+ }
122+
106123}
Original file line number Diff line number Diff line change @@ -103,4 +103,21 @@ public static function newFromNumber( $numericId ) {
103103 return new self ( 'P ' . $ numericId );
104104 }
105105
106+ /**
107+ * CAUTION: Use the full string serialization whenever you can and avoid using numeric IDs.
108+ *
109+ * @param string $repositoryName
110+ * @param int|float|string $numericId
111+ *
112+ * @return self
113+ * @throws InvalidArgumentException
114+ */
115+ public static function newFromRepositoryAndNumber ( $ repositoryName , $ numericId ) {
116+ if ( !is_numeric ( $ numericId ) ) {
117+ throw new InvalidArgumentException ( '$numericId must be numeric ' );
118+ }
119+
120+ return new self ( self ::joinSerialization ( [ $ repositoryName , '' , 'P ' . $ numericId ] ) );
121+ }
122+
106123}
Original file line number Diff line number Diff line change @@ -156,4 +156,14 @@ public function invalidNumericIdProvider() {
156156 ];
157157 }
158158
159+ public function testNewFromRepositoryAndNumber () {
160+ $ id = ItemId::newFromRepositoryAndNumber ( 'foo ' , 1 );
161+ $ this ->assertSame ( 'foo:Q1 ' , $ id ->getSerialization () );
162+ }
163+
164+ public function testNewFromRepositoryAndNumberWithInvalidNumericId () {
165+ $ this ->setExpectedException ( InvalidArgumentException::class );
166+ ItemId::newFromRepositoryAndNumber ( '' , 'Q1 ' );
167+ }
168+
159169}
Original file line number Diff line number Diff line change @@ -156,4 +156,14 @@ public function invalidNumericIdProvider() {
156156 ];
157157 }
158158
159+ public function testNewFromRepositoryAndNumber () {
160+ $ id = PropertyId::newFromRepositoryAndNumber ( 'foo ' , 1 );
161+ $ this ->assertSame ( 'foo:P1 ' , $ id ->getSerialization () );
162+ }
163+
164+ public function testNewFromRepositoryAndNumberWithInvalidNumericId () {
165+ $ this ->setExpectedException ( InvalidArgumentException::class );
166+ PropertyId::newFromRepositoryAndNumber ( '' , 'P1 ' );
167+ }
168+
159169}
You can’t perform that action at this time.
0 commit comments