Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Statement/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public function __construct( Claim $claim, ReferenceList $references = null ) {
$this->references = $references === null ? new ReferenceList() : $references;
}

/**
* @since 2.2
*
* @param Snak $mainSnak
*
* @return Statement
*/
public static function newFromMainSnak( Snak $mainSnak ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional $qualifiers and $references are missing. Which is what my #268 does, by the way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is for constructing a new instance from a main snak. Not other stuff as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we will also add newFromMainSnakAndQualifiers as well as newFromMainSnakQualifiersAndReferences? That's what optional parameters are for. That's what constructors are for. Introducing more of these static method(s) means we will replace all new Statement( ... ) calls with static Statement::new...( ... ). I don't see how this makes the overall situation better.

return new self( new Claim( $mainSnak ) );
}

/**
* Returns the references attached to this statement.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/Statement/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,11 @@ public function testGetClaim() {
$this->assertSame( $qualifiers, $claim->getQualifiers() );
}

public function testNewFromMainSnak() {
$snak = new PropertyNoValueSnak( new PropertyId( 'P42' ) );

$statement = Statement::newFromMainSnak( $snak );
$this->assertEquals( $snak, $statement->getMainSnak() );
}

}