Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ languages:
PHP: true

exclude_paths:
- "src/tests/"
- "tests/"
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Created by .ignore support plugin (hsz.mobi)

/composer.lock
/app/resources/twig/compilation_cache/
/.sass-cache/
/vendor/
/log/
/app/public/css/theme.css.map
/app/public/vendor/
/src/tests/build/
/tests/build/
/training/
14 changes: 14 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build:
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
checks:
php: true
filter: { }
coding_style:
php:
spaces:
around_operators:
concatenation: true
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml

after_script:
- php vendor/bin/coveralls -v
after_success:
- bash <(curl -s https://codecov.io/bash)
Binary file removed Observer.png
Binary file not shown.
773 changes: 0 additions & 773 deletions Observer.svg

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Build Status](https://travis-ci.org/Jagepard/PhpDesignPatterns-Observer.svg?branch=master)](https://travis-ci.org/Jagepard/PhpDesignPatterns-Observer)
[![codecov](https://codecov.io/gh/Jagepard/PhpDesignPatterns-Observer/branch/master/graph/badge.svg)](https://codecov.io/gh/Jagepard/PhpDesignPatterns-Observer)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Jagepard/PhpDesignPatterns-Observer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Jagepard/PhpDesignPatterns-Observer/?branch=master)
[![Code Climate](https://codeclimate.com/github/Jagepard/PhpDesignPatterns-Observer/badges/gpa.svg)](https://codeclimate.com/github/Jagepard/PhpDesignPatterns-Observer)

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a117b0ab-4147-43ab-b98d-c5c957a2eee3/big.png)](https://insight.sensiolabs.com/projects/a117b0ab-4147-43ab-b98d-c5c957a2eee3)

[![License: MIT](https://img.shields.io/badge/license-MIT-498e7f.svg)](https://mit-license.org/)
-----
# Observer
Наблюдатель
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description" : "PhpDesignPatterns",
"type" : "library",
"keywords" : [
"patterns",
"design-patterns"
"observer",
"design-pattern"
],
"license" : "MIT",
"authors" : [
Expand All @@ -15,22 +15,26 @@
"role" : "Developer"
}
],

"support" : {
"email": "jagepard@yandex.ru",
"skype": "jagepard.ru"
},

"require": {
"php": ">=7.0"
},
"require-dev" : {
"phpunit/phpunit": "^7"
},
"autoload": {
"psr-4": {
"Behavioral\\Observer\\":"src/"
}
},

"require": {
"php": ">=7.0"
"autoload-dev" : {
"psr-4": {
"Behavioral\\Observer\\Tests\\":"tests/"
}
},

"minimum-stability": "dev",
"prefer-stable" : true
}
13 changes: 5 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
bootstrap="src/tests/bootstrap.php"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="PhpDesignPatterns-Observer">
<directory>src/tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="src/tests/build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="src/tests/build/coverage.txt"/>
<log type="coverage-clover" target="src/tests/build/logs/clover.xml"/>
<log type="coverage-html" target="tests/build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="tests/build/coverage.txt"/>
<log type="coverage-clover" target="tests/build/logs/clover.xml"/>
</logging>
<filter>
<blacklist>
<directory suffix=".php">./vendor</directory>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<file>./src/tests/bootstrap.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
8 changes: 3 additions & 5 deletions src/EventInterface.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @copyright Copyright (c) 2017, Korotkov Danila
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
* @license https://mit-license.org/ MIT
*/

namespace Behavioral\Observer;

/**
* Interface EventInterface
*
* @package Behavioral\Observer
*/
interface EventInterface
Expand All @@ -21,5 +19,5 @@ interface EventInterface
/**
* @return string
*/
public function getEventName(): string ;
public function getName(): string;
}
16 changes: 7 additions & 9 deletions src/FootballEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @copyright Copyright (c) 2017, Korotkov Danila
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
* @license https://mit-license.org/ MIT
*/

namespace Behavioral\Observer;

/**
* Class FootballEvent
*
* @package Behavioral\Observer
*/
class FootballEvent implements EventInterface
Expand All @@ -25,22 +23,22 @@ class FootballEvent implements EventInterface
/**
* @var string
*/
protected $eventName;
protected $name;

/**
* FootballEvent constructor.
* @param string $eventName
* @param string $name
*/
public function __construct(string $eventName)
public function __construct(string $name)
{
$this->eventName = $eventName;
$this->name = $name;
}

/**
* @return string
*/
public function getEventName(): string
public function getName(): string
{
return $this->eventName;
return $this->name;
}
}
19 changes: 8 additions & 11 deletions src/FootballObserver.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @copyright Copyright (c) 2017, Korotkov Danila
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
* @license https://mit-license.org/ MIT
*/

namespace Behavioral\Observer;

/**
* Class FootballObserver
*
* @package Behavioral\Observer
*/
class FootballObserver implements ObserverInterface
Expand All @@ -21,23 +19,22 @@ class FootballObserver implements ObserverInterface
/**
* @var string
*/
protected $observerName;
protected $name;

/**
* FootballObserver constructor.
*
* @param $observerName
* @param string $name
*/
public function __construct(string $observerName)
public function __construct(string $name)
{
$this->observerName = $observerName;
$this->name = $name;
}

/**
* @return string
*/
public function getObserverName(): string
public function getName(): string
{
return $this->observerName;
return $this->name;
}
}
36 changes: 16 additions & 20 deletions src/FootballSubject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,51 @@

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @copyright Copyright (c) 2017, Korotkov Danila
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
* @license https://mit-license.org/ MIT
*/

namespace Behavioral\Observer;

/**
* Class FootballSubject
*
* @package Behavioral\Observer
*/
class FootballSubject implements SubjectInterface
{

/**
* @var array
* @var string
*/
protected $observers = [];

protected $name;
/**
* @var string
* @var array
*/
protected $subjectName;
protected $observers = [];

/**
* FootballSubject constructor.
*
* @param string $subjectName
* @param string $name
*/
public function __construct(string $subjectName)
public function __construct(string $name)
{
$this->subjectName = $subjectName;
$this->name = $name;
}

/**
* @param ObserverInterface $observer
*/
public function attachObserver(ObserverInterface $observer): void
{
$this->observers[$observer->getObserverName()] = $observer;
$this->observers[$observer->getName()] = $observer;
}

/**
* @param string $observerName
* @param string $name
*/
public function detachObserver(string $observerName): void
public function detachObserver(string $name): void
{
if (array_key_exists($observerName, $this->observers)) {
unset($this->observers[$observerName]);
if (array_key_exists($name, $this->observers)) {
unset($this->observers[$name]);
}
}

Expand All @@ -63,15 +59,15 @@ public function notify(EventInterface $event): void
{
foreach ($this->observers as $observer) {
printf("%s has get information about: %s %s \n",
$observer->getObserverName(), $this->getSubjectName(), $event->getEventName());
$observer->getName(), $this->name, $event->getName());
}
}

/**
* @return mixed
*/
public function getSubjectName(): string
public function getName(): string
{
return $this->subjectName;
return $this->name;
}
}
8 changes: 3 additions & 5 deletions src/ObserverInterface.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @copyright Copyright (c) 2017, Korotkov Danila
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
* @license https://mit-license.org/ MIT
*/

namespace Behavioral\Observer;

/**
* Interface ObserverInterface
*
* @package Behavioral\Observer
*/
interface ObserverInterface
Expand All @@ -21,5 +19,5 @@ interface ObserverInterface
/**
* @return string
*/
public function getObserverName(): string;
public function getName(): string;
}
6 changes: 2 additions & 4 deletions src/SubjectInterface.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/**
* @author : Korotkov Danila <dankorot@gmail.com>
* @copyright Copyright (c) 2017, Korotkov Danila
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
* @license https://mit-license.org/ MIT
*/

namespace Behavioral\Observer;

/**
* Interface SubjectInterface
*
* @package Behavioral\Observer
*/
interface SubjectInterface
Expand Down
3 changes: 0 additions & 3 deletions src/tests/bootstrap.php

This file was deleted.

Loading