Skip to content

Commit

Permalink
Add default type in Matrix::getInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
kunjara committed Jan 15, 2017
1 parent 965ab64 commit ce91f1d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Ganita/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

namespace Jyotish\Ganita;

use Jyotish\Ganita\Matrix\MatrixBase;

/**
* Matrix class.
*
* @author Kunjara Lila das <[email protected]>
*/
class Matrix
{
const TYPE_DEFAULT = 'default';
const TYPE_ROTATION = 'rotation';
const TYPE_TRANSLATION = 'translation';
const TYPE_REFLECTION = 'reflection';
Expand All @@ -24,6 +27,7 @@ class Matrix
* @var array
*/
public static $type = [
self::TYPE_DEFAULT,
self::TYPE_ROTATION,
self::TYPE_TRANSLATION,
self::TYPE_REFLECTION,
Expand All @@ -44,8 +48,12 @@ public static function getInstance($type, ...$params)
throw new Exception\InvalidArgumentException("Matix '$typeLower' is not defined.");
}

$matrixClass = 'Jyotish\Ganita\Matrix\\' . ucfirst($typeLower);
$matrixObject = new $matrixClass(...$params);
if ($type == Matrix::TYPE_DEFAULT) {
$matrixObject = new MatrixBase(...$params);
} else {
$matrixClass = 'Jyotish\Ganita\Matrix\\' . ucfirst($typeLower);
$matrixObject = new $matrixClass(...$params);
}

return $matrixObject;
}
Expand Down

0 comments on commit ce91f1d

Please sign in to comment.