@@ -49,16 +49,17 @@ public function canDiffEntityType( $entityType ) {
4949 * @throws InvalidArgumentException
5050 */
5151 public function diffEntities ( EntityDocument $ from , EntityDocument $ to ) {
52- $ this ->assertIsProperty ( $ from );
53- $ this ->assertIsProperty ( $ to );
52+ $ fromProperty = $ this ->assertIsPropertyAndCast ( $ from );
53+ $ toProperty = $ this ->assertIsPropertyAndCast ( $ to );
5454
55- return $ this ->diffProperties ( $ from , $ to );
55+ return $ this ->diffProperties ( $ fromProperty , $ toProperty );
5656 }
5757
58- private function assertIsProperty ( EntityDocument $ property ) {
58+ private function assertIsPropertyAndCast ( EntityDocument $ property ): Property {
5959 if ( !( $ property instanceof Property ) ) {
6060 throw new InvalidArgumentException ( '$property must be an instance of Property ' );
6161 }
62+ return $ property ;
6263 }
6364
6465 public function diffProperties ( Property $ from , Property $ to ) {
@@ -104,11 +105,10 @@ private function toDiffArray( Property $property ) {
104105 * @throws InvalidArgumentException
105106 */
106107 public function getConstructionDiff ( EntityDocument $ entity ) {
107- $ this ->assertIsProperty ( $ entity );
108+ $ property = $ this ->assertIsPropertyAndCast ( $ entity );
108109
109- /** @var Property $entity */
110- $ diffOps = $ this ->diffPropertyArrays ( [], $ this ->toDiffArray ( $ entity ) );
111- $ diffOps ['claim ' ] = $ this ->statementListDiffer ->getDiff ( new StatementList (), $ entity ->getStatements () );
110+ $ diffOps = $ this ->diffPropertyArrays ( [], $ this ->toDiffArray ( $ property ) );
111+ $ diffOps ['claim ' ] = $ this ->statementListDiffer ->getDiff ( new StatementList (), $ property ->getStatements () );
112112
113113 return new EntityDiff ( $ diffOps );
114114 }
@@ -120,11 +120,10 @@ public function getConstructionDiff( EntityDocument $entity ) {
120120 * @throws InvalidArgumentException
121121 */
122122 public function getDestructionDiff ( EntityDocument $ entity ) {
123- $ this ->assertIsProperty ( $ entity );
123+ $ property = $ this ->assertIsPropertyAndCast ( $ entity );
124124
125- /** @var Property $entity */
126- $ diffOps = $ this ->diffPropertyArrays ( $ this ->toDiffArray ( $ entity ), [] );
127- $ diffOps ['claim ' ] = $ this ->statementListDiffer ->getDiff ( $ entity ->getStatements (), new StatementList () );
125+ $ diffOps = $ this ->diffPropertyArrays ( $ this ->toDiffArray ( $ property ), [] );
126+ $ diffOps ['claim ' ] = $ this ->statementListDiffer ->getDiff ( $ property ->getStatements (), new StatementList () );
128127
129128 return new EntityDiff ( $ diffOps );
130129 }
0 commit comments