diff --git a/.phpunit.result.cache b/.phpunit.result.cache
index 6c0b0d7..19a422c 100755
--- a/.phpunit.result.cache
+++ b/.phpunit.result.cache
@@ -1 +1 @@
-C:37:"PHPUnit\Runner\DefaultTestResultCache":263:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:3:{s:59:"Behavioral\Observer\Tests\ObserverTest::testFootballSubject";d:0.001;s:54:"Behavioral\Observer\Tests\ObserverTest::testTeamAction";d:0.001;s:58:"Behavioral\Observer\Tests\ObserverTest::testDetachObserver";d:0.001;}}}
\ No newline at end of file
+{"version":1,"defects":{"Behavioral\\Observer\\Tests\\ObserverTest::testTeamAction":3},"times":{"Behavioral\\Observer\\Tests\\ObserverTest::testFootballSubject":0.001,"Behavioral\\Observer\\Tests\\ObserverTest::testTeamAction":0.005,"Behavioral\\Observer\\Tests\\ObserverTest::testDetachObserver":0.001}}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100755
index 93d3c04..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-language: php
-
-# Define the php versions against we want to test our code
-php:
- - 7.4
-
-before_script:
- - wget http://getcomposer.org/composer.phar
- - php composer.phar install --dev --no-interaction
-
-script:
- - mkdir -p build/logs
- - phpunit --coverage-clover build/logs/clover.xml
-
-after_success:
- - bash <(curl -s https://codecov.io/bash)
diff --git a/README.md b/README.md
index 665dc52..b54657f 100755
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-[](https://travis-ci.org/Jagepard/PhpDesignPatterns-Observer)
-[](https://codecov.io/gh/Jagepard/PhpDesignPatterns-Observer)
+
[](https://scrutinizer-ci.com/g/Jagepard/PhpDesignPatterns-Observer/?branch=master)
[](https://codeclimate.com/github/Jagepard/PhpDesignPatterns-Observer)
[](https://mit-license.org/)
diff --git a/api.md b/api.md
index 5efd633..ce8101a 100755
--- a/api.md
+++ b/api.md
@@ -1,71 +1,79 @@
## Table of contents
+- [Behavioral\Observer\EventInterface](#behavioral_observer_eventinterface)
+- [Behavioral\Observer\FootballEvent](#behavioral_observer_footballevent)
+- [Behavioral\Observer\FootballObserver](#behavioral_observer_footballobserver)
+- [Behavioral\Observer\FootballSubject](#behavioral_observer_footballsubject)
+- [Behavioral\Observer\NameTrait](#behavioral_observer_nametrait)
+- [Behavioral\Observer\ObserverInterface](#behavioral_observer_observerinterface)
+- [Behavioral\Observer\SubjectInterface](#behavioral_observer_subjectinterface)
+
+
+
+
+### Class: Behavioral\Observer\EventInterface
+| Visibility | Function |
+|:-----------|:---------|
+|abstract public|getName(): string
|
-- [\Behavioral\Observer\EventInterface (interface)](#interface-behavioralobservereventinterface)
-- [\Behavioral\Observer\FootballEvent](#class-behavioralobserverfootballevent)
-- [\Behavioral\Observer\FootballObserver](#class-behavioralobserverfootballobserver)
-- [\Behavioral\Observer\FootballSubject](#class-behavioralobserverfootballsubject)
-- [\Behavioral\Observer\ObserverInterface (interface)](#interface-behavioralobserverobserverinterface)
-- [\Behavioral\Observer\SubjectInterface (interface)](#interface-behavioralobserversubjectinterface)
-
-
-### Interface: \Behavioral\Observer\EventInterface
+
+### Class: Behavioral\Observer\FootballEvent
+##### implements [Behavioral\Observer\EventInterface](#behavioral_observer_eventinterface)
| Visibility | Function |
|:-----------|:---------|
-| public | getName() : mixed |
+|public|__construct( string $name )
Sets the name
Устанавливает наименование|
+|public|getName(): string
Gets a name
Получает наименование|
-
-### Class: \Behavioral\Observer\FootballEvent
+
+### Class: Behavioral\Observer\FootballObserver
+##### implements [Behavioral\Observer\ObserverInterface](#behavioral_observer_observerinterface)
| Visibility | Function |
|:-----------|:---------|
-| public | __construct(\string $name) : void |
-| public | getName() : mixed |
+|public|__construct( string $name )
Sets the name
Устанавливает наименование|
+|public|getName(): string
Gets a name
Получает наименование|
-*This class implements [\Behavioral\Observer\EventInterface](#interface-behavioralobservereventinterface)*
-
-
-### Class: \Behavioral\Observer\FootballObserver
+
+### Class: Behavioral\Observer\FootballSubject
+##### implements [Behavioral\Observer\SubjectInterface](#behavioral_observer_subjectinterface)
| Visibility | Function |
|:-----------|:---------|
-| public | __construct(\string $name) : void |
-| public | getName() : mixed |
-
-*This class implements [\Behavioral\Observer\ObserverInterface](#interface-behavioralobserverobserverinterface)*
+|public|attachObserver( Behavioral\Observer\ObserverInterface $observer ): void
Adds an observer
Добавляет наблюдателя|
+|public|detachObserver( string $name ): void
Removes an observer
Убирает наблюдателя|
+|public|notifyObservers( Behavioral\Observer\EventInterface $event ): void
Notifies all observers of an event
Уведомляет всех наблюдателей о событии|
+|public|__construct( string $name )
Sets the name
Устанавливает наименование|
+|public|getName(): string
Gets a name
Получает наименование|
-
-### Class: \Behavioral\Observer\FootballSubject
+
+### Class: Behavioral\Observer\NameTrait
| Visibility | Function |
|:-----------|:---------|
-| public | __construct(\string $name) : void |
-| public | attachObserver([\Behavioral\Observer\ObserverInterface](#interface-behavioralobserverobserverinterface) $observer) : void |
-| public | detachObserver(\string $name) : void |
-| public | getName() : mixed |
-| public | notifyObservers([\Behavioral\Observer\EventInterface](#interface-behavioralobservereventinterface) $event) : void |
-
-*This class implements [\Behavioral\Observer\SubjectInterface](#interface-behavioralobserversubjectinterface)*
+|public|__construct( string $name )
Sets the name
Устанавливает наименование|
+|public|getName(): string
Gets a name
Получает наименование|
-
-### Interface: \Behavioral\Observer\ObserverInterface
+
+### Class: Behavioral\Observer\ObserverInterface
| Visibility | Function |
|:-----------|:---------|
-| public | getName() : mixed |
+|abstract public|getName(): string
|
-
-### Interface: \Behavioral\Observer\SubjectInterface
+
+### Class: Behavioral\Observer\SubjectInterface
| Visibility | Function |
|:-----------|:---------|
-| public | attachObserver([\Behavioral\Observer\ObserverInterface](#interface-behavioralobserverobserverinterface) $observer) : void |
-| public | detachObserver(\string $observerName) : void |
-| public | notifyObservers([\Behavioral\Observer\EventInterface](#interface-behavioralobservereventinterface) $event) : void |
+|abstract public|attachObserver( Behavioral\Observer\ObserverInterface $observer ): void
|
+|abstract public|detachObserver( string $observerName ): void
|
+|abstract public|notifyObservers( Behavioral\Observer\EventInterface $event ): void
|
+
+###### created with [Rudra-Documentation-Collector](#https://github.com/Jagepard/Rudra-Documentation-Collector)
diff --git a/composer.json b/composer.json
index 84c6dd0..d20401c 100755
--- a/composer.json
+++ b/composer.json
@@ -20,10 +20,8 @@
"skype": "jagepard.ru"
},
"require": {
- "php": ">=7.4"
- },
- "require-dev" : {
- "phpunit/phpunit": "^7"
+ "php": ">=7.4",
+ "rudra/docs": "dev-master"
},
"autoload": {
"psr-4": {
diff --git a/src/EventInterface.php b/src/EventInterface.php
index 8762b25..8325143 100755
--- a/src/EventInterface.php
+++ b/src/EventInterface.php
@@ -9,5 +9,8 @@
interface EventInterface
{
+ /**
+ * @return string
+ */
public function getName(): string;
}
diff --git a/src/FootballSubject.php b/src/FootballSubject.php
index 9978702..8d6d3b0 100755
--- a/src/FootballSubject.php
+++ b/src/FootballSubject.php
@@ -15,6 +15,14 @@ class FootballSubject implements SubjectInterface
private array $observers = [];
+ /**
+ * Adds an observer
+ * ---------------------
+ * Добавляет наблюдателя
+ *
+ * @param ObserverInterface $observer
+ * @return void
+ */
public function attachObserver(ObserverInterface $observer): void
{
if (array_key_exists($observer->getName(), $this->observers)) {
@@ -24,6 +32,14 @@ public function attachObserver(ObserverInterface $observer): void
$this->observers[$observer->getName()] = $observer;
}
+ /**
+ * Removes an observer
+ * -------------------
+ * Убирает наблюдателя
+ *
+ * @param string $name
+ * @return void
+ */
public function detachObserver(string $name): void
{
if (!array_key_exists($name, $this->observers)) {
@@ -33,6 +49,14 @@ public function detachObserver(string $name): void
unset($this->observers[$name]);
}
+ /**
+ * Notifies all observers of an event
+ * --------------------------------------
+ * Уведомляет всех наблюдателей о событии
+ *
+ * @param EventInterface $event
+ * @return void
+ */
public function notifyObservers(EventInterface $event): void
{
foreach ($this->observers as $observer) {
@@ -43,5 +67,7 @@ public function notifyObservers(EventInterface $event): void
$event->getName()
);
}
+
+ print("\n");
}
}
diff --git a/src/NameTrait.php b/src/NameTrait.php
index 255fdf3..51afafa 100755
--- a/src/NameTrait.php
+++ b/src/NameTrait.php
@@ -12,11 +12,25 @@ trait NameTrait
{
private string $name;
+ /**
+ * Sets the name
+ * --------------------------
+ * Устанавливает наименование
+ *
+ * @param string $name
+ */
public function __construct(string $name)
{
$this->name = $name;
}
+ /**
+ * Gets a name
+ * ---------------------
+ * Получает наименование
+ *
+ * @return string
+ */
public function getName(): string
{
return $this->name;
diff --git a/src/ObserverInterface.php b/src/ObserverInterface.php
index b2f6494..31bc322 100755
--- a/src/ObserverInterface.php
+++ b/src/ObserverInterface.php
@@ -9,5 +9,8 @@
interface ObserverInterface
{
+ /**
+ * @return string
+ */
public function getName(): string;
}
diff --git a/src/SubjectInterface.php b/src/SubjectInterface.php
index 640297b..4ee2c50 100755
--- a/src/SubjectInterface.php
+++ b/src/SubjectInterface.php
@@ -9,7 +9,21 @@
interface SubjectInterface
{
+ /**
+ * @param ObserverInterface $observer
+ * @return void
+ */
public function attachObserver(ObserverInterface $observer): void;
+
+ /**
+ * @param string $observerName
+ * @return void
+ */
public function detachObserver(string $observerName): void;
+
+ /**
+ * @param EventInterface $event
+ * @return void
+ */
public function notifyObservers(EventInterface $event): void;
}
diff --git a/tests/ObserverTest.php b/tests/ObserverTest.php
index fcaf024..6fc985b 100755
--- a/tests/ObserverTest.php
+++ b/tests/ObserverTest.php
@@ -37,7 +37,7 @@ public function testTeamAction(): void
$goal = ob_get_clean();
$this->assertEquals(
- "John has get information about: Manchester United Goal!!! \nBill has get information about: Manchester United Goal!!! \n",
+ "John has get information about: Manchester United Goal!!! \nBill has get information about: Manchester United Goal!!! \n\n",
$goal
);
@@ -46,7 +46,7 @@ public function testTeamAction(): void
$miss = ob_get_clean();
$this->assertEquals(
- "John has get information about: Manchester United missing a ball((( \nBill has get information about: Manchester United missing a ball((( \n",
+ "John has get information about: Manchester United missing a ball((( \nBill has get information about: Manchester United missing a ball((( \n\n",
$miss
);
@@ -55,7 +55,7 @@ public function testTeamAction(): void
$violation = ob_get_clean();
$this->assertEquals(
- "John has get information about: Manchester United getting a yellow card \nBill has get information about: Manchester United getting a yellow card \n",
+ "John has get information about: Manchester United getting a yellow card \nBill has get information about: Manchester United getting a yellow card \n\n",
$violation
);
@@ -64,7 +64,7 @@ public function testTeamAction(): void
$random = ob_get_clean();
$this->assertEquals(
- "John has get information about: Manchester United random \nBill has get information about: Manchester United random \n",
+ "John has get information about: Manchester United random \nBill has get information about: Manchester United random \n\n",
$random
);
}