Skip to content

Commit

Permalink
Add class level description to DiffOpFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Apr 17, 2018
1 parent 815bfa3 commit ee7b4a3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/DiffOpFactory.php
Expand Up @@ -4,9 +4,15 @@

namespace Diff;

use Diff\DiffOp\Diff\Diff;
use Diff\DiffOp\DiffOpAdd;
use Diff\DiffOp\DiffOpChange;
use Diff\DiffOp\DiffOpRemove;
use InvalidArgumentException;

/**
* Constructs a DiffOp from its array form (which can be obtained via @see DiffOp::toArray).
*
* @since 0.5
*
* @license GPL-2.0+
Expand Down Expand Up @@ -47,18 +53,18 @@ public function newFromArray( array $diffOp ) {

if ( $diffOp['type'] === 'add' ) {
$this->assertHasKey( 'newvalue', $diffOp );
return new DiffOp\DiffOpAdd( $this->arrayToObject( $diffOp['newvalue'] ) );
return new DiffOpAdd( $this->arrayToObject( $diffOp['newvalue'] ) );
}

if ( $diffOp['type'] === 'remove' ) {
$this->assertHasKey( 'oldvalue', $diffOp );
return new DiffOp\DiffOpRemove( $this->arrayToObject( $diffOp['oldvalue'] ) );
return new DiffOpRemove( $this->arrayToObject( $diffOp['oldvalue'] ) );
}

if ( $diffOp['type'] === 'change' ) {
$this->assertHasKey( 'newvalue', $diffOp );
$this->assertHasKey( 'oldvalue', $diffOp );
return new DiffOp\DiffOpChange(
return new DiffOpChange(
$this->arrayToObject( $diffOp['oldvalue'] ),
$this->arrayToObject( $diffOp['newvalue'] ) );
}
Expand All @@ -73,7 +79,7 @@ public function newFromArray( array $diffOp ) {
$operations[$key] = $this->newFromArray( $operation );
}

return new DiffOp\Diff\Diff( $operations, $diffOp['isassoc'] );
return new Diff( $operations, $diffOp['isassoc'] );
}

throw new InvalidArgumentException( 'Invalid array provided. Unknown type' );
Expand Down

0 comments on commit ee7b4a3

Please sign in to comment.