diff --git a/Event/EventManager.php b/Event/EventManager.php index a2219b410..6c38ca897 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -63,9 +63,15 @@ class EventManager implements Mediator /** * {@inheritdoc} */ - public function attach(string $group, \Closure $callback, bool $remove = false) + public function attach(string $group, \Closure $callback, bool $remove = false) : bool { + if(isset($this->callbacks[$group])) { + return false; + } + $this->callbacks[$group] = ['remove' => $remove, 'func' => $callback]; + + return true; } /** @@ -87,7 +93,7 @@ class EventManager implements Mediator /** * {@inheritdoc} */ - public function trigger(string $id, string $group) + public function trigger(string $group, string $id = 0) { if(isset($this->groups[$group])) { unset($this->groups[$group][$id]); @@ -113,7 +119,7 @@ class EventManager implements Mediator /** * {@inheritdoc} */ - public function addGroup(string $id, string $group) + public function addGroup(string $group, $id) { if(!isset($this->groups[$group])) { $this->groups[$group] = []; diff --git a/Math/Number/Integer.php b/Math/Number/Integer.php index ae85cac73..e187eb475 100644 --- a/Math/Number/Integer.php +++ b/Math/Number/Integer.php @@ -145,14 +145,14 @@ class Integer * @param int $value Integer to factorize * @param int $limit Max amount of iterations * - * @return int + * @return array * * @throws \Exception * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function fermatFactor(int $value, int $limit = 1000000) : int + public static function fermatFactor(int $value, int $limit = 1000000) : array { if (($value % 2) !== 0) { throw new \Exception('Only odd integers are allowed'); @@ -167,6 +167,6 @@ class Integer $b2 = $a * $a - $value; } - return (int) round($a - sqrt($b2)); + return [(int) round($a - sqrt($b2)), (int) round($a + sqrt($b2))]; } } \ No newline at end of file diff --git a/Math/Shape/D2/Circle.php b/Math/Shape/D2/Circle.php index ab190e1cd..d47c958dc 100644 --- a/Math/Shape/D2/Circle.php +++ b/Math/Shape/D2/Circle.php @@ -39,7 +39,7 @@ class Circle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $r) + public static function getSurface(float $r) : float { return pi() * $r ** 2; } @@ -54,7 +54,7 @@ class Circle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getPerimeter(float $r) + public static function getPerimeter(float $r) : float { return 2 * pi() * $r; } @@ -69,7 +69,7 @@ class Circle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getRadiusBySurface(float $surface) + public static function getRadiusBySurface(float $surface) : float { return sqrt($surface / pi()); } @@ -84,7 +84,7 @@ class Circle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getRadiusByPerimeter(float $C) + public static function getRadiusByPerimeter(float $C) : float { return $C / (2 * pi()); } diff --git a/Math/Shape/D2/Rectangle.php b/Math/Shape/D2/Rectangle.php index ba28302e6..9ad3e9b12 100644 --- a/Math/Shape/D2/Rectangle.php +++ b/Math/Shape/D2/Rectangle.php @@ -40,7 +40,7 @@ class Rectangle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $a, float $b) + public static function getSurface(float $a, float $b) : float { return $a * $b; } @@ -56,7 +56,7 @@ class Rectangle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getPerimeter(float $a, float $b) + public static function getPerimeter(float $a, float $b) : float { return 2 * ($a + $b); } @@ -72,7 +72,7 @@ class Rectangle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getDiagonal(float $a, float $b) + public static function getDiagonal(float $a, float $b) : float { return sqrt($a * $a + $b * $b); } diff --git a/Math/Shape/D2/Trapezoid.php b/Math/Shape/D2/Trapezoid.php index 569e6a3f8..18c22e823 100644 --- a/Math/Shape/D2/Trapezoid.php +++ b/Math/Shape/D2/Trapezoid.php @@ -47,7 +47,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $a, float $b, float $h) + public static function getSurface(float $a, float $b, float $h) : float { return ($a + $b) / 2 * $h; } @@ -71,7 +71,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getPerimeter(float $a, float $b, float $c, float $d) + public static function getPerimeter(float $a, float $b, float $c, float $d) : float { return $a + $b + $c + $d; } @@ -94,7 +94,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getHeight(float $area, float $a, float $b) + public static function getHeight(float $area, float $a, float $b) : float { return 2 * $area / ($a + $b); } @@ -117,7 +117,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getA(float $area, float $h, float $b) + public static function getA(float $area, float $h, float $b) : float { return 2 * $area / $h - $b; } @@ -140,7 +140,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getB(float $area, float $h, float $a) + public static function getB(float $area, float $h, float $a) : float { return 2 * $area / $h - $a; } @@ -164,7 +164,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getC(float $perimeter, float $a, float $b, float $d) + public static function getC(float $perimeter, float $a, float $b, float $d) : float { return $perimeter - $a - $b - $d; } @@ -188,7 +188,7 @@ class Trapezoid implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getD(float $perimeter, float $a, float $b, float $c) + public static function getD(float $perimeter, float $a, float $b, float $c) : float { return $perimeter - $a - $b - $c; } diff --git a/Math/Shape/D2/Triangle.php b/Math/Shape/D2/Triangle.php index 07e1d2fd2..5ae7f666c 100644 --- a/Math/Shape/D2/Triangle.php +++ b/Math/Shape/D2/Triangle.php @@ -46,7 +46,7 @@ class Triangle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $b, float $h) + public static function getSurface(float $b, float $h) : float { return $h * $b / 2; } @@ -63,7 +63,7 @@ class Triangle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getPerimeter(float $a, float $b, float $c) + public static function getPerimeter(float $a, float $b, float $c) : float { return $a + $b + $c; } @@ -79,7 +79,7 @@ class Triangle implements D2ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getHeight(float $area, float $b) + public static function getHeight(float $area, float $b) : float { return 2 * $area / $b; } diff --git a/Math/Shape/D3/Cone.php b/Math/Shape/D3/Cone.php index 3b4efdce6..bd8ddb98a 100644 --- a/Math/Shape/D3/Cone.php +++ b/Math/Shape/D3/Cone.php @@ -40,7 +40,7 @@ class Cone implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getVolume(float $r, float $h) + public static function getVolume(float $r, float $h) : float { return pi() * $r ** 2 * $h / 3; } @@ -56,7 +56,7 @@ class Cone implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $r, float $h) + public static function getSurface(float $r, float $h) : float { return pi() * $r * ($r + sqrt($h ** 2 + $r ** 2)); } @@ -72,7 +72,7 @@ class Cone implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSlantHeight(float $r, float $h) + public static function getSlantHeight(float $r, float $h) : float { return sqrt($h ** 2 + $r ** 2); } @@ -88,7 +88,7 @@ class Cone implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getHeight(float $V, float $r) + public static function getHeight(float $V, float $r) : float { return 4 * $V / (pi() * $r ** 2); } diff --git a/Math/Shape/D3/Cuboid.php b/Math/Shape/D3/Cuboid.php index 39468e1c6..e9cb74edc 100644 --- a/Math/Shape/D3/Cuboid.php +++ b/Math/Shape/D3/Cuboid.php @@ -41,7 +41,7 @@ class Cuboid implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getVolume(float $a, float $b, float $h) + public static function getVolume(float $a, float $b, float $h) : float { return $a * $b * $h; } @@ -58,7 +58,7 @@ class Cuboid implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $a, float $b, float $h) + public static function getSurface(float $a, float $b, float $h) : float { return 2 * ($a * $b + $a * $h + $b * $h); } diff --git a/Math/Shape/D3/Cylinder.php b/Math/Shape/D3/Cylinder.php index a4d49f1cb..0f2a83013 100644 --- a/Math/Shape/D3/Cylinder.php +++ b/Math/Shape/D3/Cylinder.php @@ -40,7 +40,7 @@ class Cylinder implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getVolume(float $r, float $h) + public static function getVolume(float $r, float $h) : float { return pi() * $r ** 2 * $h; } @@ -56,7 +56,7 @@ class Cylinder implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $r, float $h) + public static function getSurface(float $r, float $h) : float { return 2 * pi() * ($r * $h + $r ** 2); } @@ -72,7 +72,7 @@ class Cylinder implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getLateralSurface(float $r, float $h) + public static function getLateralSurface(float $r, float $h) : float { return 2 * pi() * $r * $h; } diff --git a/Math/Shape/D3/RectangularPyramid.php b/Math/Shape/D3/RectangularPyramid.php index cdbf6bbac..53acd63aa 100644 --- a/Math/Shape/D3/RectangularPyramid.php +++ b/Math/Shape/D3/RectangularPyramid.php @@ -41,7 +41,7 @@ class RectangularPyramid implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getVolume(float $a, float $b, float $h) + public static function getVolume(float $a, float $b, float $h) : float { return $a * $b * $h / 3; } @@ -58,7 +58,7 @@ class RectangularPyramid implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $a, float $b, float $h) + public static function getSurface(float $a, float $b, float $h) : float { return $a * $b + $a * sqrt(($b / 2) ** 2 + $h ** 2) + $b * sqrt(($a / 2) ** 2 + $h ** 2); } @@ -75,7 +75,7 @@ class RectangularPyramid implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getLateralSurface(float $a, float $b, float $h) + public static function getLateralSurface(float $a, float $b, float $h) : float { return $a * sqrt(($b / 2) ** 2 + $h ** 2) + $b * sqrt(($a / 2) ** 2 + $h ** 2); } diff --git a/Math/Shape/D3/Tetrahedron.php b/Math/Shape/D3/Tetrahedron.php index b4dff1cb6..0515e733a 100644 --- a/Math/Shape/D3/Tetrahedron.php +++ b/Math/Shape/D3/Tetrahedron.php @@ -39,7 +39,7 @@ class Tetrahedron implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getVolume(float $a) + public static function getVolume(float $a) : float { return $a ** 3 / (6 * sqrt(2)); } @@ -54,7 +54,7 @@ class Tetrahedron implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getSurface(float $a) + public static function getSurface(float $a) : float { return sqrt(3) * $a ** 2; } @@ -69,7 +69,7 @@ class Tetrahedron implements D3ShapeInterface * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getFaceArea(float $a) + public static function getFaceArea(float $a) : float { return sqrt(3) / 4 * $a ** 2; } diff --git a/Pattern/Mediator.php b/Pattern/Mediator.php index ab1b65352..6317f344d 100644 --- a/Pattern/Mediator.php +++ b/Pattern/Mediator.php @@ -62,28 +62,28 @@ interface Mediator extends \Countable * * Add new element to group * - * @param string $id Event ID * @param string $group Group + * @param string $id Event ID * * @return void * * @since 1.0.0 * @author Dennis Eichhorn */ - public function addGroup(string $id, string $group); + public function addGroup(string $group, string $id); /** * Trigger event. * * An object fires an event * - * @param string $id Event ID * @param string $group Group + * @param string $id Event ID * * @return void * * @since 1.0.0 * @author Dennis Eichhorn */ - public function trigger(string $id, string $group); + public function trigger(string $group, string $id); }