Page MenuHomeDevCentral

D2674.id6760.largetrue.diff
No OneTemporary

D2674.id6760.largetrue.diff

This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/.arclint b/.arclint
--- a/.arclint
+++ b/.arclint
@@ -28,9 +28,14 @@
"phpcs": {
"type": "phpcs",
"bin": "vendor/bin/phpcs",
- "phpcs.standard": "PSR1",
- "include": "(^app/.*\\.php$)"
- },
+ "phpcs.standard": "phpcs.xml",
+ "include": [
+ "(app/.*\\.php$)",
+ "(config/.*\\.php$)",
+ "(tests/.*\\.php$)"
+
+ ]
+},
"spelling": {
"type": "spelling"
},
diff --git a/app/Actions/AMQPAction.php b/app/Actions/AMQPAction.php
--- a/app/Actions/AMQPAction.php
+++ b/app/Actions/AMQPAction.php
@@ -3,43 +3,43 @@
namespace Nasqueron\Notifications\Actions;
class AMQPAction extends Action {
- /**
- * The action done on the broker ('publish', 'consume')
- *
- * @var string
- */
- public $method;
+ /**
+ * The action done on the broker ('publish', 'consume')
+ *
+ * @var string
+ */
+ public $method;
- /**
- * The queue or exchange target on the broker
- *
- * @var string
- */
- public $target;
+ /**
+ * The queue or exchange target on the broker
+ *
+ * @var string
+ */
+ public $target;
- /**
- * The routing key
- *
- * @var string
- */
- public $routingKey;
+ /**
+ * The routing key
+ *
+ * @var string
+ */
+ public $routingKey;
- /**
- * Initializes a new instance of a AMQP action to report
- *
- * @param string $method The action done on the broker (e.g. 'publish')
- * @param string $target The queue or exchange target on the broker
- * @param string $routingKey The routing key for this exchange or queue
- */
- public function __construct (
- string $method,
- string $target,
- string $routingKey = ''
- ) {
- parent::__construct();
+ /**
+ * Initializes a new instance of a AMQP action to report
+ *
+ * @param string $method The action done on the broker (e.g. 'publish')
+ * @param string $target The queue or exchange target on the broker
+ * @param string $routingKey The routing key for this exchange or queue
+ */
+ public function __construct(
+ string $method,
+ string $target,
+ string $routingKey = ''
+ ) {
+ parent::__construct();
- $this->method = $method;
- $this->target = $target;
- $this->routingKey = $routingKey;
- }
+ $this->method = $method;
+ $this->target = $target;
+ $this->routingKey = $routingKey;
+ }
}
diff --git a/app/Actions/Action.php b/app/Actions/Action.php
--- a/app/Actions/Action.php
+++ b/app/Actions/Action.php
@@ -3,34 +3,34 @@
namespace Nasqueron\Notifications\Actions;
abstract class Action {
- /**
- * @var string
- */
- public $action;
+ /**
+ * @var string
+ */
+ public $action;
- /**
- * @var ActionError
- */
- public $error;
+ /**
+ * @var ActionError
+ */
+ public $error;
- /**
- * Initializes a new instance of an action to report
- */
- public function __construct () {
- $this->action = class_basename(get_called_class());
- }
+ /**
+ * Initializes a new instance of an action to report
+ */
+ public function __construct() {
+ $this->action = class_basename( get_called_class() );
+ }
- /**
- * Attaches an error to the action to report
- *
- * To attach an exception, you can use:
- * <code>
- * $actionToReport->attachError(new ActionError($exception));
- * </code>
- *
- * @param ActionError $error The error to attach
- */
- public function attachError (ActionError $error) : void {
- $this->error = $error;
- }
+ /**
+ * Attaches an error to the action to report
+ *
+ * To attach an exception, you can use:
+ * <code>
+ * $actionToReport->attachError(new ActionError($exception));
+ * </code>
+ *
+ * @param ActionError $error The error to attach
+ */
+ public function attachError( ActionError $error ): void {
+ $this->error = $error;
+ }
}
diff --git a/app/Actions/ActionError.php b/app/Actions/ActionError.php
--- a/app/Actions/ActionError.php
+++ b/app/Actions/ActionError.php
@@ -4,22 +4,22 @@
class ActionError {
- /**
- * Exception type
- *
- * @var string
- */
- public $type;
+ /**
+ * Exception type
+ *
+ * @var string
+ */
+ public $type;
- /**
- * Exception message
- *
- * @var string
- */
- public $message;
+ /**
+ * Exception message
+ *
+ * @var string
+ */
+ public $message;
- public function __construct (\Exception $ex) {
- $this->type = class_basename(get_class($ex));
- $this->message = $ex->getMessage();
- }
+ public function __construct( \Exception $ex ) {
+ $this->type = class_basename( get_class( $ex ) );
+ $this->message = $ex->getMessage();
+ }
}
diff --git a/app/Actions/ActionsReport.php b/app/Actions/ActionsReport.php
--- a/app/Actions/ActionsReport.php
+++ b/app/Actions/ActionsReport.php
@@ -3,88 +3,88 @@
namespace Nasqueron\Notifications\Actions;
class ActionsReport {
- /**
- * List of actions
- *
- * @var Action[]
- */
- public $actions = [];
+ /**
+ * List of actions
+ *
+ * @var Action[]
+ */
+ public $actions = [];
- /**
- * Report created date
- *
- * @var int
- */
- public $created;
+ /**
+ * Report created date
+ *
+ * @var int
+ */
+ public $created;
- /**
- * The entry gate
- *
- * @var string
- */
- public $gate;
+ /**
+ * The entry gate
+ *
+ * @var string
+ */
+ public $gate;
- /**
- * The entry door
- *
- * @var string
- */
- public $door;
+ /**
+ * The entry door
+ *
+ * @var string
+ */
+ public $door;
- /**
- * Initializes a new instance of an actions report
- */
- public function __construct () {
- $this->created = time();
- }
+ /**
+ * Initializes a new instance of an actions report
+ */
+ public function __construct() {
+ $this->created = time();
+ }
- ///
- /// Properties
- ///
+ ///
+ /// Properties
+ ///
- /**
- * Sets the gate and the door for this report
- *
- * @param string $gate The gate
- * @param string $door The door
- */
- public function attachToGate (string $gate, string $door) : void {
- $this->gate = $gate;
- $this->door = $door;
- }
+ /**
+ * Sets the gate and the door for this report
+ *
+ * @param string $gate The gate
+ * @param string $door The door
+ */
+ public function attachToGate( string $gate, string $door ): void {
+ $this->gate = $gate;
+ $this->door = $door;
+ }
- /**
- * Adds an action to the list of actions to report
- *
- * @param Action $action The action to add
- */
- public function addAction (Action $action) : void {
- $this->actions[] = $action;
- }
+ /**
+ * Adds an action to the list of actions to report
+ *
+ * @param Action $action The action to add
+ */
+ public function addAction( Action $action ): void {
+ $this->actions[] = $action;
+ }
- /**
- * Determines if one of the action has failed.
- *
- * @return bool
- */
- public function containsError () : bool {
- foreach ($this->actions as $action) {
- if ($action->error !== null) {
- return true;
- }
- }
+ /**
+ * Determines if one of the action has failed.
+ *
+ * @return bool
+ */
+ public function containsError(): bool {
+ foreach ( $this->actions as $action ) {
+ if ( $action->error !== null ) {
+ return true;
+ }
+ }
- return false;
- }
+ return false;
+ }
- ///
- /// Output
- ///
+ ///
+ /// Output
+ ///
- /**
- * Gets a JSON string representation of the current instance
- */
- public function __toString () : string {
- return json_encode($this, JSON_PRETTY_PRINT);
- }
+ /**
+ * Gets a JSON string representation of the current instance
+ */
+ public function __toString(): string {
+ return json_encode( $this, JSON_PRETTY_PRINT );
+ }
}
diff --git a/app/Actions/NotifyNewCommitsAction.php b/app/Actions/NotifyNewCommitsAction.php
--- a/app/Actions/NotifyNewCommitsAction.php
+++ b/app/Actions/NotifyNewCommitsAction.php
@@ -3,21 +3,21 @@
namespace Nasqueron\Notifications\Actions;
class NotifyNewCommitsAction extends Action {
- /**
- * The Phabricator repository call sign
- *
- * @var string
- */
- public $callSign;
+ /**
+ * The Phabricator repository call sign
+ *
+ * @var string
+ */
+ public $callSign;
- /**
- * Initializes a new instance of a AMQP action to report.
- *
- * @param string $callSign The Phabricator repository call sign
- */
- public function __construct (string $callSign) {
- parent::__construct();
+ /**
+ * Initializes a new instance of a AMQP action to report.
+ *
+ * @param string $callSign The Phabricator repository call sign
+ */
+ public function __construct( string $callSign ) {
+ parent::__construct();
- $this->callSign = $callSign;
- }
+ $this->callSign = $callSign;
+ }
}
diff --git a/app/Actions/TriggerDockerHubBuildAction.php b/app/Actions/TriggerDockerHubBuildAction.php
--- a/app/Actions/TriggerDockerHubBuildAction.php
+++ b/app/Actions/TriggerDockerHubBuildAction.php
@@ -3,21 +3,21 @@
namespace Nasqueron\Notifications\Actions;
class TriggerDockerHubBuildAction extends Action {
- /**
- * The Docker Hub image
- *
- * @var string
- */
- public $image;
+ /**
+ * The Docker Hub image
+ *
+ * @var string
+ */
+ public $image;
- /**
- * Initializes a new instance of a DockerHub build trigger action to report
- *
- * @param string $image The Docker Hub image to trigger
- */
- public function __construct (string $image) {
- parent::__construct();
+ /**
+ * Initializes a new instance of a DockerHub build trigger action to report
+ *
+ * @param string $image The Docker Hub image to trigger
+ */
+ public function __construct( string $image ) {
+ parent::__construct();
- $this->image = $image;
- }
+ $this->image = $image;
+ }
}
diff --git a/app/Analyzers/BasePayloadAnalyzer.php b/app/Analyzers/BasePayloadAnalyzer.php
--- a/app/Analyzers/BasePayloadAnalyzer.php
+++ b/app/Analyzers/BasePayloadAnalyzer.php
@@ -2,180 +2,179 @@
namespace Nasqueron\Notifications\Analyzers;
+use BadMethodCallException;
use Config;
use Storage;
-use BadMethodCallException;
-
abstract class BasePayloadAnalyzer {
- ///
- /// Constants
- ///
-
- /**
- * The name of the service, used to get specific classes and config
- */
- const SERVICE_NAME = "UnknownService";
-
- ///
- /// Private members
- ///
-
- /**
- * The project name, used to load specific configuration and offer defaults
- * @var string
- */
- protected $project;
-
- /**
- * The request content, as a structured data
- * @var \stdClass
- */
- protected $payload;
-
- /**
- * The configuration for the payload analyzer
- * @var PayloadAnalyzerConfiguration;
- */
- protected $configuration;
-
- ///
- /// Constructor
- ///
-
- /**
- * Creates a new JenkinsPayloadAnalyzer instance.
- *
- * @param string $project
- * @param \stdClass $payload
- */
- public function __construct(string $project, \stdClass $payload) {
- $this->project = $project;
- $this->payload = $payload;
-
- $this->loadConfiguration();
- }
-
- ///
- /// Configuration
- ///
-
- /**
- * The default name of the configuration file
- */
- const CONFIG_DEFAULT_FILE = 'default.json';
-
- /**
- * Gets the full path to the configuration file.
- *
- * @return string
- */
- public function getConfigurationFileName () : string {
- $dir = Config::get(
- 'services.'
- . strtolower(static::SERVICE_NAME)
- . '.analyzer.configDir'
- );
-
- $filename = $dir . '/' . $this->project . '.json';
-
- if (!Storage::has($filename)) {
- return $dir . '/' . static::CONFIG_DEFAULT_FILE;
- }
-
- return $filename;
- }
-
- /**
- * Gets full qualified class name for configuration.
- *
- * @return string
- */
- private function getCandidateConfigurationClassName() : string {
- return 'Nasqueron\Notifications\Analyzers\\' . static::SERVICE_NAME //ns
- . "\\"
- . static::SERVICE_NAME . 'PayloadAnalyzerConfiguration'; // class
- }
-
- /**
- * Gets full qualified class name for configuration if existing,
- * or PayloadAnalyzerConfiguration class if not.
- *
- * @return string The configuration class to use
- */
- private function getConfigurationClassName () : string {
- $class = $this->getCandidateConfigurationClassName();
-
- if (class_exists($class)) {
- return $class;
- }
-
- return PayloadAnalyzerConfiguration::class;
- }
-
- /**
- * Loads configuration for the analyzer
- */
- public function loadConfiguration () : void {
- $fileName = $this->getConfigurationFileName();
- $class = $this->getConfigurationClassName();
-
- $mapper = new \JsonMapper();
- $this->configuration = $mapper->map(
- json_decode(Storage::get($fileName)),
- new $class($this->project)
- );
- }
-
- ///
- /// Properties
- ///
-
- /**
- * Gets the name of the item.
- *
- * @var string
- */
- public function getItemName () : string {
- throw new BadMethodCallException(<<<MSG
+ ///
+ /// Constants
+ ///
+
+ /**
+ * The name of the service, used to get specific classes and config
+ */
+ const SERVICE_NAME = "UnknownService";
+
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The project name, used to load specific configuration and offer defaults
+ * @var string
+ */
+ protected $project;
+
+ /**
+ * The request content, as a structured data
+ * @var \stdClass
+ */
+ protected $payload;
+
+ /**
+ * The configuration for the payload analyzer
+ * @var PayloadAnalyzerConfiguration
+ */
+ protected $configuration;
+
+ ///
+ /// Constructor
+ ///
+
+ /**
+ * Creates a new JenkinsPayloadAnalyzer instance.
+ *
+ * @param string $project
+ * @param \stdClass $payload
+ */
+ public function __construct( string $project, \stdClass $payload ) {
+ $this->project = $project;
+ $this->payload = $payload;
+
+ $this->loadConfiguration();
+ }
+
+ ///
+ /// Configuration
+ ///
+
+ /**
+ * The default name of the configuration file
+ */
+ const CONFIG_DEFAULT_FILE = 'default.json';
+
+ /**
+ * Gets the full path to the configuration file.
+ *
+ * @return string
+ */
+ public function getConfigurationFileName(): string {
+ $dir = Config::get(
+ 'services.'
+ . strtolower( static::SERVICE_NAME )
+ . '.analyzer.configDir'
+ );
+
+ $filename = $dir . '/' . $this->project . '.json';
+
+ if ( !Storage::has( $filename ) ) {
+ return $dir . '/' . static::CONFIG_DEFAULT_FILE;
+ }
+
+ return $filename;
+ }
+
+ /**
+ * Gets full qualified class name for configuration.
+ *
+ * @return string
+ */
+ private function getCandidateConfigurationClassName(): string {
+ return 'Nasqueron\Notifications\Analyzers\\' . static::SERVICE_NAME // ns
+ . "\\"
+ . static::SERVICE_NAME . 'PayloadAnalyzerConfiguration'; // class
+ }
+
+ /**
+ * Gets full qualified class name for configuration if existing,
+ * or PayloadAnalyzerConfiguration class if not.
+ *
+ * @return string The configuration class to use
+ */
+ private function getConfigurationClassName(): string {
+ $class = $this->getCandidateConfigurationClassName();
+
+ if ( class_exists( $class ) ) {
+ return $class;
+ }
+
+ return PayloadAnalyzerConfiguration::class;
+ }
+
+ /**
+ * Loads configuration for the analyzer
+ */
+ public function loadConfiguration(): void {
+ $fileName = $this->getConfigurationFileName();
+ $class = $this->getConfigurationClassName();
+
+ $mapper = new \JsonMapper();
+ $this->configuration = $mapper->map(
+ json_decode( Storage::get( $fileName ) ),
+ new $class( $this->project )
+ );
+ }
+
+ ///
+ /// Properties
+ ///
+
+ /**
+ * Gets the name of the item.
+ *
+ * @var string
+ */
+ public function getItemName(): string {
+ throw new BadMethodCallException( <<<MSG
The getItemName method must be implemented in the analyzer class if used.
MSG
);
- }
-
- /**
- * Determines if the event isn't related to a specific item,
- * but to the general service.
- *
- * @return bool
- */
- public function isAdministrativeEvent () : bool {
- return false;
- }
-
- /**
- * Gets the group for a specific payload.
- *
- * @return string The group, central part of the routing key
- */
- public function getGroup () : string {
- // Some events are organization-level only and can't be mapped
- // to projects.
- if ($this->isAdministrativeEvent()) {
- return $this->configuration->administrativeGroup;
- }
-
- // If the payload is about some repository matching a table of
- // symbols, we need to sort it to the right group.
- $item = $this->getItemName();
- foreach ($this->configuration->map as $mapping) {
- if ($mapping->doesItemBelong($item)) {
- return $mapping->group;
- }
- }
-
- return $this->configuration->getDefaultGroup();
- }
+ }
+
+ /**
+ * Determines if the event isn't related to a specific item,
+ * but to the general service.
+ *
+ * @return bool
+ */
+ public function isAdministrativeEvent(): bool {
+ return false;
+ }
+
+ /**
+ * Gets the group for a specific payload.
+ *
+ * @return string The group, central part of the routing key
+ */
+ public function getGroup(): string {
+ // Some events are organization-level only and can't be mapped
+ // to projects.
+ if ( $this->isAdministrativeEvent() ) {
+ return $this->configuration->administrativeGroup;
+ }
+
+ // If the payload is about some repository matching a table of
+ // symbols, we need to sort it to the right group.
+ $item = $this->getItemName();
+ foreach ( $this->configuration->map as $mapping ) {
+ if ( $mapping->doesItemBelong( $item ) ) {
+ return $mapping->group;
+ }
+ }
+
+ return $this->configuration->getDefaultGroup();
+ }
}
diff --git a/app/Analyzers/DockerHub/BaseEvent.php b/app/Analyzers/DockerHub/BaseEvent.php
--- a/app/Analyzers/DockerHub/BaseEvent.php
+++ b/app/Analyzers/DockerHub/BaseEvent.php
@@ -4,45 +4,45 @@
abstract class BaseEvent {
- /**
- * @var \stdClass
- */
- protected $payload;
-
- /**
- * Initializes a new instance of the BaseEvent object.
- *
- * @param \stdClass $payload The payload to analyze
- */
- public function __construct ($payload) {
- $this->payload = $payload;
- }
-
- ///
- /// Public methods
- ///
-
- /**
- * Gets notification payload.
- *
- * This method allows analyzer to edit the payload.
- */
- public function getPayload () {
- return $this->payload;
- }
-
- /**
- * Gets notification text for this event.
- *
- * @return string
- */
- abstract public function getText();
-
- /**
- * Gets notification link related to this event.
- *
- * @return string
- */
- abstract public function getLink();
+ /**
+ * @var \stdClass
+ */
+ protected $payload;
+
+ /**
+ * Initializes a new instance of the BaseEvent object.
+ *
+ * @param \stdClass $payload The payload to analyze
+ */
+ public function __construct( $payload ) {
+ $this->payload = $payload;
+ }
+
+ ///
+ /// Public methods
+ ///
+
+ /**
+ * Gets notification payload.
+ *
+ * This method allows analyzer to edit the payload.
+ */
+ public function getPayload() {
+ return $this->payload;
+ }
+
+ /**
+ * Gets notification text for this event.
+ *
+ * @return string
+ */
+ abstract public function getText();
+
+ /**
+ * Gets notification link related to this event.
+ *
+ * @return string
+ */
+ abstract public function getLink();
}
diff --git a/app/Analyzers/DockerHub/BuildFailureEvent.php b/app/Analyzers/DockerHub/BuildFailureEvent.php
--- a/app/Analyzers/DockerHub/BuildFailureEvent.php
+++ b/app/Analyzers/DockerHub/BuildFailureEvent.php
@@ -6,62 +6,62 @@
class BuildFailureEvent extends BaseEvent {
- /**
- * Initializes a new instance of the BuildFailureEvent object.
- *
- * @param \stdClass $payload The payload to analyze
- */
- public function __construct ($payload) {
- parent::__construct($payload);
- $this->payload = $this->getMailGunPayload();
- }
+ /**
+ * Initializes a new instance of the BuildFailureEvent object.
+ *
+ * @param \stdClass $payload The payload to analyze
+ */
+ public function __construct( $payload ) {
+ parent::__construct( $payload );
+ $this->payload = $this->getMailGunPayload();
+ }
- /**
- * Gets a MailGun message.
- *
- * @return \stdClass
- */
- private function getMailGunPayload () {
- return Mailgun::fetchMessageFromPayload($this->payload);
- }
+ /**
+ * Gets a MailGun message.
+ *
+ * @return \stdClass
+ */
+ private function getMailGunPayload() {
+ return Mailgun::fetchMessageFromPayload( $this->payload );
+ }
- /**
- * @return string
- */
- private function getMailBody () {
- $bodyProperty = 'body-plain';
- return $this->payload->$bodyProperty;
- }
+ /**
+ * @return string
+ */
+ private function getMailBody() {
+ $bodyProperty = 'body-plain';
+ return $this->payload->$bodyProperty;
+ }
- /**
- * Extracts a regular expression from the mail body.
- *
- * @param $string Regular expression
- * @return string
- */
- private function extractFromBody ($regex) {
- preg_match($regex, $this->getMailBody(), $matches);
- return $matches[1];
- }
+ /**
+ * Extracts a regular expression from the mail body.
+ *
+ * @param $string Regular expression
+ * @return string
+ */
+ private function extractFromBody( $regex ) {
+ preg_match( $regex, $this->getMailBody(), $matches );
+ return $matches[1];
+ }
- /**
- * Gets text from payload.
- *
- * @return string
- */
- public function getText() {
- $repo = $this->extractFromBody("@\"(.*?\/.*?)\"@");
+ /**
+ * Gets text from payload.
+ *
+ * @return string
+ */
+ public function getText() {
+ $repo = $this->extractFromBody( "@\"(.*?\/.*?)\"@" );
- return "Image build by Docker Hub registry failure for $repo";
- }
+ return "Image build by Docker Hub registry failure for $repo";
+ }
- /**
- * Gets link from payload.
- *
- * @return string
- */
- public function getLink() {
- return $this->extractFromBody("@(https\:\/\/hub.docker.com\/r.*)@");
- }
+ /**
+ * Gets link from payload.
+ *
+ * @return string
+ */
+ public function getLink() {
+ return $this->extractFromBody( "@(https\:\/\/hub.docker.com\/r.*)@" );
+ }
}
diff --git a/app/Analyzers/DockerHub/PushEvent.php b/app/Analyzers/DockerHub/PushEvent.php
--- a/app/Analyzers/DockerHub/PushEvent.php
+++ b/app/Analyzers/DockerHub/PushEvent.php
@@ -4,25 +4,25 @@
class PushEvent extends BaseEvent {
- /**
- * Gets text from payload.
- *
- * @return string
- */
- public function getText() {
- $repo = $this->payload->repository->repo_name;
- $who = $this->payload->push_data->pusher;
+ /**
+ * Gets text from payload.
+ *
+ * @return string
+ */
+ public function getText() {
+ $repo = $this->payload->repository->repo_name;
+ $who = $this->payload->push_data->pusher;
- return "New image pushed to Docker Hub registry for $repo by $who";
- }
+ return "New image pushed to Docker Hub registry for $repo by $who";
+ }
- /**
- * Gets link from payload.
- *
- * @return string
- */
- public function getLink() {
- return $this->payload->repository->repo_url;
- }
+ /**
+ * Gets link from payload.
+ *
+ * @return string
+ */
+ public function getLink() {
+ return $this->payload->repository->repo_url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/CommitCommentEvent.php b/app/Analyzers/GitHub/Events/CommitCommentEvent.php
--- a/app/Analyzers/GitHub/Events/CommitCommentEvent.php
+++ b/app/Analyzers/GitHub/Events/CommitCommentEvent.php
@@ -9,30 +9,30 @@
*/
class CommitCommentEvent extends Event {
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- $comment = $this->payload->comment;
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $comment = $this->payload->comment;
- return trans(
- 'GitHub.EventsDescriptions.CommitCommentEvent',
- [
- 'author' => $comment->user->login,
- 'commit' => substr($comment->commit_id, 0, 8),
- 'excerpt' => self::cut($comment->body),
- ]
- );
- }
+ return trans(
+ 'GitHub.EventsDescriptions.CommitCommentEvent',
+ [
+ 'author' => $comment->user->login,
+ 'commit' => substr( $comment->commit_id, 0, 8 ),
+ 'excerpt' => self::cut( $comment->body ),
+ ]
+ );
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- return $this->payload->comment->html_url;
- }
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->payload->comment->html_url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/CreateEvent.php b/app/Analyzers/GitHub/Events/CreateEvent.php
--- a/app/Analyzers/GitHub/Events/CreateEvent.php
+++ b/app/Analyzers/GitHub/Events/CreateEvent.php
@@ -15,64 +15,64 @@
*/
class CreateEvent extends Event {
- use WithRef;
+ use WithRef;
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- $repository = $this->payload->repository->full_name;
- $type = $this->payload->ref_type;
- $ref = $this->payload->ref;
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $repository = $this->payload->repository->full_name;
+ $type = $this->payload->ref_type;
+ $ref = $this->payload->ref;
- if (!self::isValidRefType($type)) {
- return trans(
- 'GitHub.EventsDescriptions.CreateEventUnknown',
- [
- 'type' => $type,
- 'ref' => $ref,
- ]
- );
- }
+ if ( !self::isValidRefType( $type ) ) {
+ return trans(
+ 'GitHub.EventsDescriptions.CreateEventUnknown',
+ [
+ 'type' => $type,
+ 'ref' => $ref,
+ ]
+ );
+ }
- return trans(
- 'GitHub.EventsDescriptions.CreateEvent',
- [
- 'type' => $type,
- 'ref' => $ref,
- 'repository' => $repository,
- ]
- );
- }
+ return trans(
+ 'GitHub.EventsDescriptions.CreateEvent',
+ [
+ 'type' => $type,
+ 'ref' => $ref,
+ 'repository' => $repository,
+ ]
+ );
+ }
- /**
- * Gets link segments for the type
- *
- * @return array
- * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
- */
- private function getLinkRefSegments () : array {
- return [
- 'tag' => '/releases/tag/',
- 'branch' => '/tree/',
- ];
- }
+ /**
+ * Gets link segments for the type
+ *
+ * @return array
+ * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
+ */
+ private function getLinkRefSegments(): array {
+ return [
+ 'tag' => '/releases/tag/',
+ 'branch' => '/tree/',
+ ];
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- $type = $this->payload->ref_type;
- $ref = $this->payload->ref;
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ $type = $this->payload->ref_type;
+ $ref = $this->payload->ref;
- $url = $this->payload->repository->html_url;
- $url .= $this->getLinkRefSegment($type);
- $url .= $ref;
+ $url = $this->payload->repository->html_url;
+ $url .= $this->getLinkRefSegment( $type );
+ $url .= $ref;
- return $url;
- }
+ return $url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/DeleteEvent.php b/app/Analyzers/GitHub/Events/DeleteEvent.php
--- a/app/Analyzers/GitHub/Events/DeleteEvent.php
+++ b/app/Analyzers/GitHub/Events/DeleteEvent.php
@@ -12,62 +12,62 @@
*/
class DeleteEvent extends Event {
- use WithRef;
+ use WithRef;
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- $repository = $this->payload->repository->full_name;
- $type = $this->payload->ref_type;
- $ref = $this->payload->ref;
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $repository = $this->payload->repository->full_name;
+ $type = $this->payload->ref_type;
+ $ref = $this->payload->ref;
- if (!self::isValidRefType($type)) {
- return trans(
- 'GitHub.EventsDescriptions.DeleteEventUnknown',
- [
- 'type' => $type,
- 'ref' => $ref,
- ]
- );
- }
+ if ( !self::isValidRefType( $type ) ) {
+ return trans(
+ 'GitHub.EventsDescriptions.DeleteEventUnknown',
+ [
+ 'type' => $type,
+ 'ref' => $ref,
+ ]
+ );
+ }
- return trans(
- 'GitHub.EventsDescriptions.DeleteEvent',
- [
- 'type' => $type,
- 'ref' => $ref,
- 'repository' => $repository,
- ]
- );
- }
+ return trans(
+ 'GitHub.EventsDescriptions.DeleteEvent',
+ [
+ 'type' => $type,
+ 'ref' => $ref,
+ 'repository' => $repository,
+ ]
+ );
+ }
- /**
- * Gets link segments for the type
- *
- * @return Array
- * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
- */
- private function getLinkRefSegments () {
- return [
- 'tag' => '/tags',
- 'branch' => '/branches',
- ];
- }
+ /**
+ * Gets link segments for the type
+ *
+ * @return array
+ * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
+ */
+ private function getLinkRefSegments() {
+ return [
+ 'tag' => '/tags',
+ 'branch' => '/branches',
+ ];
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- $type = $this->payload->ref_type;
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ $type = $this->payload->ref_type;
- $url = $this->payload->repository->html_url;
- $url .= $this->getLinkRefSegment($type);
+ $url = $this->payload->repository->html_url;
+ $url .= $this->getLinkRefSegment( $type );
- return $url;
- }
+ return $url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/Event.php b/app/Analyzers/GitHub/Events/Event.php
--- a/app/Analyzers/GitHub/Events/Event.php
+++ b/app/Analyzers/GitHub/Events/Event.php
@@ -2,79 +2,81 @@
namespace Nasqueron\Notifications\Analyzers\GitHub\Events;
+use Illuminate\Support\Str;
+
class Event {
- ///
- /// Properties
- ///
+ ///
+ /// Properties
+ ///
- /**
- * The payload
- *
- * @var \stdClass
- */
- protected $payload;
+ /**
+ * The payload
+ *
+ * @var \stdClass
+ */
+ protected $payload;
- ///
- /// Constructor
- ///
+ ///
+ /// Constructor
+ ///
- public function __construct ($payload) {
- $this->payload = $payload;
- }
+ public function __construct( $payload ) {
+ $this->payload = $payload;
+ }
- ///
- /// Gets or initialize relevant class
- ///
+ ///
+ /// Gets or initialize relevant class
+ ///
- /**
- * Gets class name from the GitHub webhooks event name
- *
- * @param string $eventName The event name (e.g. commit_comment)
- * @return string The event class name (e.g. CommitCommentEvent)
- */
- public static function getClass ($eventName) {
- return __NAMESPACE__ . '\\' . studly_case($eventName) . 'Event';
- }
+ /**
+ * Gets class name from the GitHub webhooks event name
+ *
+ * @param string $eventName The event name (e.g. commit_comment)
+ * @return string The event class name (e.g. CommitCommentEvent)
+ */
+ public static function getClass( string $eventName ) {
+ return __NAMESPACE__ . '\\' . Str::studly( $eventName ) . 'Event';
+ }
- /**
- * Gets an instance of the event class, from the
- *
- * @param string $eventName The event name (e.g. commit_comment)
- * @return Event
- */
- public static function forPayload ($eventName, $payload) {
- $class = self::getClass($eventName);
- if (!class_exists($class)) {
- throw new \InvalidArgumentException(
- "Class doesn't exist: $class (for $eventName)"
- );
- }
- return new $class($payload);
- }
+ /**
+ * Gets an instance of the event class, from the
+ *
+ * @param string $eventName The event name (e.g. commit_comment)
+ * @return Event
+ */
+ public static function forPayload( string $eventName, $payload ) {
+ $class = self::getClass( $eventName );
+ if ( !class_exists( $class ) ) {
+ throw new \InvalidArgumentException(
+ "Class doesn't exist: $class (for $eventName)"
+ );
+ }
+ return new $class( $payload );
+ }
- ///
- /// Helper methods
- ///
+ ///
+ /// Helper methods
+ ///
- /**
- * Cuts a text
- *
- * @param string $text The text to cut
- * @param int $strLen The amount of characters to allow [optional]
- * @param string $symbol The symbol to append to a cut text [optional]
- */
- public static function cut ($text, $strLen = 114, $symbol = '…') {
- $len = strlen($text);
- if ($len <= $strLen) {
- return $text;
- }
+ /**
+ * Cuts a text
+ *
+ * @param string $text The text to cut
+ * @param int $strLen The amount of characters to allow [optional]
+ * @param string $symbol The symbol to append to a cut text [optional]
+ */
+ public static function cut( string $text, int $strLen = 114, string $symbol = '…' ) {
+ $len = strlen( $text );
+ if ( $len <= $strLen ) {
+ return $text;
+ }
- if ($strLen < 1) {
- return $symbol;
- }
+ if ( $strLen < 1 ) {
+ return $symbol;
+ }
- return substr($text, 0, $strLen - 1) . $symbol;
- }
+ return substr( $text, 0, $strLen - 1 ) . $symbol;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/ForkEvent.php b/app/Analyzers/GitHub/Events/ForkEvent.php
--- a/app/Analyzers/GitHub/Events/ForkEvent.php
+++ b/app/Analyzers/GitHub/Events/ForkEvent.php
@@ -11,27 +11,27 @@
*/
class ForkEvent extends Event {
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- return trans(
- 'GitHub.EventsDescriptions.ForkEvent',
- [
- 'repo_base' => $this->payload->repository->full_name,
- 'repo_fork' => $this->payload->forkee->full_name,
- ]
- );
- }
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ return trans(
+ 'GitHub.EventsDescriptions.ForkEvent',
+ [
+ 'repo_base' => $this->payload->repository->full_name,
+ 'repo_fork' => $this->payload->forkee->full_name,
+ ]
+ );
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- return $this->payload->forkee->html_url;
- }
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->payload->forkee->html_url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/IssueCommentEvent.php b/app/Analyzers/GitHub/Events/IssueCommentEvent.php
--- a/app/Analyzers/GitHub/Events/IssueCommentEvent.php
+++ b/app/Analyzers/GitHub/Events/IssueCommentEvent.php
@@ -9,57 +9,56 @@
*/
class IssueCommentEvent extends Event {
- /**
- * Determines if the action is valid.
- *
- * @param string $action The action to check
- * @return bool true if the action is valid; otherwise, false
- */
- protected static function isValidAction ($action) {
- $actions = ['created', 'edited', 'deleted'];
- return in_array($action, $actions);
- }
+ /**
+ * Determines if the action is valid.
+ *
+ * @param string $action The action to check
+ * @return bool true if the action is valid; otherwise, false
+ */
+ protected static function isValidAction( string $action ) {
+ $actions = [ 'created', 'edited', 'deleted' ];
+ return in_array( $action, $actions );
+ }
- /**
- * Gets description for the payload.
- *
- * @return string
- */
- public function getDescription () : string {
- $action = $this->payload->action;
+ /**
+ * Gets description for the payload.
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $action = $this->payload->action;
- if (!static::isValidAction($action)) {
- return trans(
- 'GitHub.EventsDescriptions.IssueCommentEventUnknown',
- ['action' => $action]
- );
- }
+ if ( !static::isValidAction( $action ) ) {
+ return trans(
+ 'GitHub.EventsDescriptions.IssueCommentEventUnknown',
+ [ 'action' => $action ]
+ );
+ }
- $key = 'GitHub.EventsDescriptions.IssueCommentEventPerAction.';
- $key .= $action;
+ $key = 'GitHub.EventsDescriptions.IssueCommentEventPerAction.';
+ $key .= $action;
- $comment = $this->payload->comment;
- $issue = $this->payload->issue;
+ $comment = $this->payload->comment;
+ $issue = $this->payload->issue;
- return trans(
- $key,
- [
- 'author' => $comment->user->login,
- 'issueNumber' => $issue->number,
- 'issueTitle' => $issue->title,
- 'excerpt' => self::cut($comment->body),
- ]
- );
- }
+ return trans(
+ $key,
+ [
+ 'author' => $comment->user->login,
+ 'issueNumber' => $issue->number,
+ 'issueTitle' => $issue->title,
+ 'excerpt' => self::cut( $comment->body ),
+ ]
+ );
+ }
- /**
- * Gets link for the payload.
- *
- * @return string
- */
- public function getLink () : string {
- return $this->payload->comment->html_url;
- }
+ /**
+ * Gets link for the payload.
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->payload->comment->html_url;
+ }
}
-
diff --git a/app/Analyzers/GitHub/Events/PingEvent.php b/app/Analyzers/GitHub/Events/PingEvent.php
--- a/app/Analyzers/GitHub/Events/PingEvent.php
+++ b/app/Analyzers/GitHub/Events/PingEvent.php
@@ -9,27 +9,27 @@
*/
class PingEvent extends Event {
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- return trans(
- 'GitHub.EventsDescriptions.PingEvent',
- [
- 'zen' => $this->payload->zen,
- 'hook_id' => $this->payload->hook_id,
- ]
- );
- }
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ return trans(
+ 'GitHub.EventsDescriptions.PingEvent',
+ [
+ 'zen' => $this->payload->zen,
+ 'hook_id' => $this->payload->hook_id,
+ ]
+ );
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- return '';
- }
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return '';
+ }
}
diff --git a/app/Analyzers/GitHub/Events/PullRequestEvent.php b/app/Analyzers/GitHub/Events/PullRequestEvent.php
--- a/app/Analyzers/GitHub/Events/PullRequestEvent.php
+++ b/app/Analyzers/GitHub/Events/PullRequestEvent.php
@@ -9,83 +9,83 @@
*/
class PullRequestEvent extends Event {
- /**
- * Determines if the action is valid.
- *
- * @param string $action The action to check
- * @return bool true if the action is valid; otherwise, false
- */
- protected static function isValidAction ($action) {
- $actions = [
- 'assigned', 'unassigned',
- 'labeled', 'unlabeled',
- 'opened', 'closed',
- 'edited', 'reopened',
- ];
- return in_array($action, $actions);
- }
+ /**
+ * Determines if the action is valid.
+ *
+ * @param string $action The action to check
+ * @return bool true if the action is valid; otherwise, false
+ */
+ protected static function isValidAction( string $action ) {
+ $actions = [
+ 'assigned', 'unassigned',
+ 'labeled', 'unlabeled',
+ 'opened', 'closed',
+ 'edited', 'reopened',
+ ];
+ return in_array( $action, $actions );
+ }
- /**
- * Gets description for the payload.
- *
- * @return string
- */
- public function getDescription () : string {
- $action = $this->payload->action;
+ /**
+ * Gets description for the payload.
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $action = $this->payload->action;
- if (!static::isValidAction($action)) {
- return trans(
- 'GitHub.EventsDescriptions.PullRequestEventUnknown',
- ['action' => $action]
- );
- }
+ if ( !static::isValidAction( $action ) ) {
+ return trans(
+ 'GitHub.EventsDescriptions.PullRequestEventUnknown',
+ [ 'action' => $action ]
+ );
+ }
- $key = 'GitHub.EventsDescriptions.PullRequestEventPerAction.';
- $key .= $action;
+ $key = 'GitHub.EventsDescriptions.PullRequestEventPerAction.';
+ $key .= $action;
- return trans($key, $this->getLocalisationParameters());
- }
+ return trans( $key, $this->getLocalisationParameters() );
+ }
- /**
- * Gets the parameters to pass to the localisation message
- *
- * @return array
- */
- private function getLocalisationParameters () {
- $parameters = [
- 'author' => $this->payload->sender->login,
- 'number' => $this->payload->number,
- 'title' => $this->payload->pull_request->title,
- ];
- switch ($this->payload->action) {
- case 'assigned':
- $parameters['assignee'] = $this->getLastAssignee();
- break;
- }
- return $parameters;
- }
+ /**
+ * Gets the parameters to pass to the localisation message
+ *
+ * @return array
+ */
+ private function getLocalisationParameters() {
+ $parameters = [
+ 'author' => $this->payload->sender->login,
+ 'number' => $this->payload->number,
+ 'title' => $this->payload->pull_request->title,
+ ];
+ switch ( $this->payload->action ) {
+ case 'assigned':
+ $parameters['assignee'] = $this->getLastAssignee();
+ break;
+ }
+ return $parameters;
+ }
- /**
- * @return string The last assignee username, or "" if there is no assignee.
- */
- private function getLastAssignee() {
- $assignees = $this->payload->pull_request->assignees;
+ /**
+ * @return string The last assignee username, or "" if there is no assignee.
+ */
+ private function getLastAssignee() {
+ $assignees = $this->payload->pull_request->assignees;
- if (count($assignees) === 0) {
- return ""; // No assignee.
- }
+ if ( count( $assignees ) === 0 ) {
+ return ""; // No assignee.
+ }
- $assignee = array_pop($assignees);
- return $assignee->login;
- }
+ $assignee = array_pop( $assignees );
+ return $assignee->login;
+ }
- /**
- * Gets link for the payload.
- *
- * @return string
- */
- public function getLink () : string {
- return $this->payload->pull_request->html_url;
- }
+ /**
+ * Gets link for the payload.
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->payload->pull_request->html_url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/PushEvent.php b/app/Analyzers/GitHub/Events/PushEvent.php
--- a/app/Analyzers/GitHub/Events/PushEvent.php
+++ b/app/Analyzers/GitHub/Events/PushEvent.php
@@ -9,59 +9,59 @@
*/
class PushEvent extends Event {
- use WithCommit;
- use WithRepoAndBranch;
+ use WithCommit;
+ use WithRepoAndBranch;
- /**
- * Gets the description message key according the amount of commits
- *
- * @param int $count The count of commits
- * @return string The l10n message key for description
- */
- private static function getDescriptionMessageKey ($count) {
- $key = 'GitHub.EventsDescriptions.PushEvent';
+ /**
+ * Gets the description message key according the amount of commits
+ *
+ * @param int $count The count of commits
+ * @return string The l10n message key for description
+ */
+ private static function getDescriptionMessageKey( int $count ) {
+ $key = 'GitHub.EventsDescriptions.PushEvent';
- if ($count === 0) {
- return $key . '.0';
- }
+ if ( $count === 0 ) {
+ return $key . '.0';
+ }
- return $key . '.n';
- }
+ return $key . '.n';
+ }
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- $n = count($this->payload->commits);
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $n = count( $this->payload->commits );
- if ($n === 1) {
- // If only one commit is pushed at the time,
- // we want a description for this commit.
- return $this->getHeadCommitDescription();
- }
+ if ( $n === 1 ) {
+ // If only one commit is pushed at the time,
+ // we want a description for this commit.
+ return $this->getHeadCommitDescription();
+ }
- // Otherwise, we want a description for the push.
- return trans(self::getDescriptionMessageKey($n), [
- 'user' => $this->payload->pusher->name,
- 'count' => $n,
- 'repoAndBranch' => $this->getWhere(),
- ]);
- }
+ // Otherwise, we want a description for the push.
+ return trans( self::getDescriptionMessageKey( $n ), [
+ 'user' => $this->payload->pusher->name,
+ 'count' => $n,
+ 'repoAndBranch' => $this->getWhere(),
+ ] );
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- $n = count($this->payload->commits);
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ $n = count( $this->payload->commits );
- if ($n === 1) {
- return $this->payload->head_commit->url;
- }
+ if ( $n === 1 ) {
+ return $this->payload->head_commit->url;
+ }
- return $this->payload->compare;
- }
+ return $this->payload->compare;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/RepositoryEvent.php b/app/Analyzers/GitHub/Events/RepositoryEvent.php
--- a/app/Analyzers/GitHub/Events/RepositoryEvent.php
+++ b/app/Analyzers/GitHub/Events/RepositoryEvent.php
@@ -9,58 +9,58 @@
*/
class RepositoryEvent extends Event {
- /**
- * Determines if the action is valid.
- *
- * @param string $action The action to check
- * @return bool true if the action is valid; otherwise, false
- */
- protected static function isValidAction ($action) {
- $actions = ['created', 'deleted', 'publicized', 'privatized'];
- return in_array($action, $actions);
- }
+ /**
+ * Determines if the action is valid.
+ *
+ * @param string $action The action to check
+ * @return bool true if the action is valid; otherwise, false
+ */
+ protected static function isValidAction( string $action ) {
+ $actions = [ 'created', 'deleted', 'publicized', 'privatized' ];
+ return in_array( $action, $actions );
+ }
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- $action = $this->payload->action;
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ $action = $this->payload->action;
- if (!static::isValidAction($action)) {
- return trans(
- 'GitHub.EventsDescriptions.RepositoryEventUnknown',
- ['action' => $action]
- );
- }
+ if ( !static::isValidAction( $action ) ) {
+ return trans(
+ 'GitHub.EventsDescriptions.RepositoryEventUnknown',
+ [ 'action' => $action ]
+ );
+ }
- $key = 'GitHub.EventsDescriptions.RepositoryEventPerAction.';
- $key .= $action;
+ $key = 'GitHub.EventsDescriptions.RepositoryEventPerAction.';
+ $key .= $action;
- $repository = $this->payload->repository->full_name;
+ $repository = $this->payload->repository->full_name;
- $message = trans($key, ['repository' => $repository]);
+ $message = trans( $key, [ 'repository' => $repository ] );
- if ($this->payload->repository->fork) {
- $message .= trans('GitHub.EventsDescriptions.RepositoryEventFork');
- }
+ if ( $this->payload->repository->fork ) {
+ $message .= trans( 'GitHub.EventsDescriptions.RepositoryEventFork' );
+ }
- $description = (string)$this->payload->repository->description;
- if ($description !== "") {
- $message .= trans('GitHub.Separator');
- $message .= $description;
- }
+ $description = (string)$this->payload->repository->description;
+ if ( $description !== "" ) {
+ $message .= trans( 'GitHub.Separator' );
+ $message .= $description;
+ }
- return $message;
- }
+ return $message;
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- return $this->payload->repository->html_url;
- }
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->payload->repository->html_url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/StatusEvent.php b/app/Analyzers/GitHub/Events/StatusEvent.php
--- a/app/Analyzers/GitHub/Events/StatusEvent.php
+++ b/app/Analyzers/GitHub/Events/StatusEvent.php
@@ -9,57 +9,57 @@
*/
class StatusEvent extends Event {
- /**
- * Gets state localized message
- *
- * @return string
- */
- private function getState () {
- $state = $this->payload->state; // pending, success, failure, or error
- $key = 'GitHub.StatusEventState.' . $state;
- return trans($key);
- }
+ /**
+ * Gets state localized message
+ *
+ * @return string
+ */
+ private function getState() {
+ $state = $this->payload->state; // pending, success, failure, or error
+ $key = 'GitHub.StatusEventState.' . $state;
+ return trans( $key );
+ }
- /**
- * Gets status result
- *
- * @return string
- */
- private function getStatusResult () {
- $glue = trans('GitHub.Separator');
- $fragments = array_filter([
- $this->payload->context,
- $this->payload->description,
- $this->getState(),
- ]);
+ /**
+ * Gets status result
+ *
+ * @return string
+ */
+ private function getStatusResult() {
+ $glue = trans( 'GitHub.Separator' );
+ $fragments = array_filter( [
+ $this->payload->context,
+ $this->payload->description,
+ $this->getState(),
+ ] );
- return implode($glue, $fragments);
- }
+ return implode( $glue, $fragments );
+ }
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- return trans('GitHub.EventsDescriptions.StatusEvent', [
- 'commit' => substr($this->payload->sha, 0, 8),
- 'status' => $this->getStatusResult(),
- ]);
- }
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ return trans( 'GitHub.EventsDescriptions.StatusEvent', [
+ 'commit' => substr( $this->payload->sha, 0, 8 ),
+ 'status' => $this->getStatusResult(),
+ ] );
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- $url = $this->payload->target_url;
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ $url = $this->payload->target_url;
- if ($url === null) {
- return "";
- }
+ if ( $url === null ) {
+ return "";
+ }
- return $url;
- }
+ return $url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/UnknownEvent.php b/app/Analyzers/GitHub/Events/UnknownEvent.php
--- a/app/Analyzers/GitHub/Events/UnknownEvent.php
+++ b/app/Analyzers/GitHub/Events/UnknownEvent.php
@@ -9,37 +9,37 @@
*/
class UnknownEvent extends Event {
- /**
- * @var string
- */
- private $eventType;
+ /**
+ * @var string
+ */
+ private $eventType;
- /**
- * Initializes a new instance of the UnknownEvent class, an Event analyzer
- * class to handle unknown events type.
- *
- * @param string $eventType The event type (e.g. push)
- */
- public function __construct ($eventType, $payload = null) {
- $this->eventType = $eventType;
- parent::__construct($payload);
- }
+ /**
+ * Initializes a new instance of the UnknownEvent class, an Event analyzer
+ * class to handle unknown events type.
+ *
+ * @param string $eventType The event type (e.g. push)
+ */
+ public function __construct( $eventType, $payload = null ) {
+ $this->eventType = $eventType;
+ parent::__construct( $payload );
+ }
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- return "Some $this->eventType happened";
- }
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ return "Some $this->eventType happened";
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- return "";
- }
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return "";
+ }
}
diff --git a/app/Analyzers/GitHub/Events/WatchEvent.php b/app/Analyzers/GitHub/Events/WatchEvent.php
--- a/app/Analyzers/GitHub/Events/WatchEvent.php
+++ b/app/Analyzers/GitHub/Events/WatchEvent.php
@@ -15,27 +15,27 @@
*/
class WatchEvent extends Event {
- /**
- * Gets description for the payload
- *
- * @return string
- */
- public function getDescription () : string {
- return trans(
- 'GitHub.EventsDescriptions.WatchEvent',
- [
- 'user' => $this->payload->sender->login,
- 'repository' => $this->payload->repository->full_name,
- ]
- );
- }
+ /**
+ * Gets description for the payload
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ return trans(
+ 'GitHub.EventsDescriptions.WatchEvent',
+ [
+ 'user' => $this->payload->sender->login,
+ 'repository' => $this->payload->repository->full_name,
+ ]
+ );
+ }
- /**
- * Gets link for the payload
- *
- * @return string
- */
- public function getLink () : string {
- return $this->payload->sender->html_url;
- }
+ /**
+ * Gets link for the payload
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->payload->sender->html_url;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/WithCommit.php b/app/Analyzers/GitHub/Events/WithCommit.php
--- a/app/Analyzers/GitHub/Events/WithCommit.php
+++ b/app/Analyzers/GitHub/Events/WithCommit.php
@@ -10,55 +10,55 @@
*/
trait WithCommit {
- /**
- * Gets the title of the head commit
- *
- * @return string
- */
- private function getHeadCommitTitle () {
- return static::getCommitTitle($this->payload->head_commit->message);
- }
+ /**
+ * Gets the title of the head commit
+ *
+ * @return string
+ */
+ private function getHeadCommitTitle() {
+ return static::getCommitTitle( $this->payload->head_commit->message );
+ }
- /**
- * Extracts the commit title from the whole commit message.
- *
- * @param string $message The commit message
- * @return string The commit title
- */
- public static function getCommitTitle ($message) {
- // Discards extra lines
- $pos = strpos($message, "\n");
- if ($pos > 0) {
- $message = substr($message, 0, $pos);
- }
+ /**
+ * Extracts the commit title from the whole commit message.
+ *
+ * @param string $message The commit message
+ * @return string The commit title
+ */
+ public static function getCommitTitle( string $message ) {
+ // Discards extra lines
+ $pos = strpos( $message, "\n" );
+ if ( $pos > 0 ) {
+ $message = substr( $message, 0, $pos );
+ }
- // Short messages are returned as is
- // Longer messages are truncated
- return self::cut($message, 72);
- }
+ // Short messages are returned as is
+ // Longer messages are truncated
+ return self::cut( $message, 72 );
+ }
- /**
- * Gets the description text for the head commit.
- *
- * @return string
- */
- private function getHeadCommitDescription () {
- $commit = $this->payload->head_commit;
- $committer = $commit->committer->username;
- $author = $commit->author->username;
+ /**
+ * Gets the description text for the head commit.
+ *
+ * @return string
+ */
+ private function getHeadCommitDescription() {
+ $commit = $this->payload->head_commit;
+ $committer = $commit->committer->username;
+ $author = $commit->author->username;
- $message = trans('GitHub.Commits.Message', [
- 'committer' => $committer,
- 'title' => $this->getHeadCommitTitle(),
- ]);
-
- if ($committer !== $author) {
- $message .= trans('GitHub.Commits.Authored', [
- 'author' => $author,
- ]);
- }
+ $message = trans( 'GitHub.Commits.Message', [
+ 'committer' => $committer,
+ 'title' => $this->getHeadCommitTitle(),
+ ] );
- return $message;
- }
+ if ( $committer !== $author ) {
+ $message .= trans( 'GitHub.Commits.Authored', [
+ 'author' => $author,
+ ] );
+ }
+
+ return $message;
+ }
}
diff --git a/app/Analyzers/GitHub/Events/WithRef.php b/app/Analyzers/GitHub/Events/WithRef.php
--- a/app/Analyzers/GitHub/Events/WithRef.php
+++ b/app/Analyzers/GitHub/Events/WithRef.php
@@ -11,33 +11,33 @@
*/
trait WithRef {
- /**
- * Determines if the ref type is valid.
- *
- * The ref type 'repository' is deemed invalid, as we shouldn't receive it.
- *
- * @param string $type The ref type to check
- * @return bool true if the ref type id valid; otherwise, false
- */
- protected static function isValidRefType ($type) {
- $types = ['branch', 'tag'];
- return in_array($type, $types);
- }
+ /**
+ * Determines if the ref type is valid.
+ *
+ * The ref type 'repository' is deemed invalid, as we shouldn't receive it.
+ *
+ * @param string $type The ref type to check
+ * @return bool true if the ref type id valid; otherwise, false
+ */
+ protected static function isValidRefType( string $type ) {
+ $types = [ 'branch', 'tag' ];
+ return in_array( $type, $types );
+ }
- /**
- * Gets link ref segment for the payload
- *
- * @param string $type The reference type
- * @return string the part of the URL for this reference type (e.g. /tree/)
- */
- protected function getLinkRefSegment ($type) {
- $segments = $this->getLinkRefSegments();
+ /**
+ * Gets link ref segment for the payload
+ *
+ * @param string $type The reference type
+ * @return string the part of the URL for this reference type (e.g. /tree/)
+ */
+ protected function getLinkRefSegment( string $type ) {
+ $segments = $this->getLinkRefSegments();
- if (!array_key_exists($type, $segments)) {
- throw new \InvalidArgumentException;
- }
+ if ( !array_key_exists( $type, $segments ) ) {
+ throw new \InvalidArgumentException;
+ }
- return $segments[$type];
- }
+ return $segments[$type];
+ }
}
diff --git a/app/Analyzers/GitHub/Events/WithRepoAndBranch.php b/app/Analyzers/GitHub/Events/WithRepoAndBranch.php
--- a/app/Analyzers/GitHub/Events/WithRepoAndBranch.php
+++ b/app/Analyzers/GitHub/Events/WithRepoAndBranch.php
@@ -10,36 +10,36 @@
*/
trait WithRepoAndBranch {
- /**
- * Gets repository and branch information
- */
- public function getWhere () : string {
- $repo = $this->payload->repository->name;
- $branch = $this->payload->ref;
-
- return static::getRepositoryAndBranch($repo, $branch);
- }
-
- public static function getRepositoryAndBranch (
- $repo = "",
- $branch = ""
- ) : string {
- if ($repo === "") {
- return "";
- }
-
- if (starts_with($branch, "refs/heads/")) {
- $branch = substr($branch, 11);
- }
-
- if ($branch === "" || $branch === "master") {
- return $repo;
- }
-
- return trans('GitHub.RepoAndBranch', [
- 'repo' => $repo,
- 'branch' => $branch,
- ]);
- }
+ /**
+ * Gets repository and branch information
+ */
+ public function getWhere(): string {
+ $repo = $this->payload->repository->name;
+ $branch = $this->payload->ref;
+
+ return static::getRepositoryAndBranch( $repo, $branch );
+ }
+
+ public static function getRepositoryAndBranch(
+ $repo = "",
+ $branch = ""
+ ): string {
+ if ( $repo === "" ) {
+ return "";
+ }
+
+ if ( str_starts_with( $branch, "refs/heads/" ) ) {
+ $branch = substr( $branch, 11 );
+ }
+
+ if ( $branch === "" || $branch === "master" ) {
+ return $repo;
+ }
+
+ return trans( 'GitHub.RepoAndBranch', [
+ 'repo' => $repo,
+ 'branch' => $branch,
+ ] );
+ }
}
diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
--- a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
+++ b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
@@ -8,109 +8,109 @@
class GitHubPayloadAnalyzer extends BasePayloadAnalyzer {
- /**
- * The name of the service, used to get specific classes and config
- */
- const SERVICE_NAME = "GitHub";
-
- ///
- /// Private members
- ///
-
- /**
- * The GitHub event triggering this request
- * @var string
- */
- private $event;
-
- /**
- * The payload analyzer event
- *
- * @var \Nasqueron\Notifications\Analyzers\GitHub\Events\Event;
- */
- private $analyzerEvent;
-
- ///
- /// Constructor
- ///
-
- /**
- * Creates a new GitHubPayloadAnalyzer instance.
- *
- * @param string $project
- * @param string $event
- * @param \stdClass $payload
- */
- public function __construct(
- string $project,
- string $event,
- \stdClass $payload
- ) {
- parent::__construct($project, $payload);
-
- $this->event = $event;
-
- try {
- $this->analyzerEvent = Event::forPayload($event, $payload);
- } catch (\InvalidArgumentException $ex) {
- $this->analyzerEvent = new UnknownEvent($event);
- }
- }
-
- ///
- /// Properties
- ///
-
- /**
- * Gets the name of the item, ie here of the name of the repository.
- *
- * @var string
- */
- public function getItemName () : string {
- if ($this->isAdministrativeEvent()) {
- return '';
- }
-
- return $this->payload->repository->name;
- }
-
- ///
- /// Qualification of the payload
- ///
-
- /**
- * @return bool
- */
- public function isAdministrativeEvent () : bool {
- $administrativeEvents = [
- 'membership', // Member added to team
- 'ping', // Special ping pong event, fired on new hook
- 'repository', // Repository created
- ];
-
- return in_array($this->event, $administrativeEvents);
- }
-
- ///
- /// Description of the payload
- ///
-
- /**
- * Gets a short textual description of the event.
- *
- * @return string
- */
- public function getDescription () : string {
- return $this->analyzerEvent->getDescription();
- }
-
- /**
- * Gets a link to view the event on GitHub.
- *
- * @return string The most relevant URL
- */
- public function getLink () : string {
- return $this->analyzerEvent->getLink();
- }
+ /**
+ * The name of the service, used to get specific classes and config
+ */
+ const SERVICE_NAME = "GitHub";
+
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The GitHub event triggering this request
+ * @var string
+ */
+ private $event;
+
+ /**
+ * The payload analyzer event
+ *
+ * @var \Nasqueron\Notifications\Analyzers\GitHub\Events\Event
+ */
+ private $analyzerEvent;
+
+ ///
+ /// Constructor
+ ///
+
+ /**
+ * Creates a new GitHubPayloadAnalyzer instance.
+ *
+ * @param string $project
+ * @param string $event
+ * @param \stdClass $payload
+ */
+ public function __construct(
+ string $project,
+ string $event,
+ \stdClass $payload
+ ) {
+ parent::__construct( $project, $payload );
+
+ $this->event = $event;
+
+ try {
+ $this->analyzerEvent = Event::forPayload( $event, $payload );
+ } catch ( \InvalidArgumentException $ex ) {
+ $this->analyzerEvent = new UnknownEvent( $event );
+ }
+ }
+
+ ///
+ /// Properties
+ ///
+
+ /**
+ * Gets the name of the item, ie here of the name of the repository.
+ *
+ * @var string
+ */
+ public function getItemName(): string {
+ if ( $this->isAdministrativeEvent() ) {
+ return '';
+ }
+
+ return $this->payload->repository->name;
+ }
+
+ ///
+ /// Qualification of the payload
+ ///
+
+ /**
+ * @return bool
+ */
+ public function isAdministrativeEvent(): bool {
+ $administrativeEvents = [
+ 'membership', // Member added to team
+ 'ping', // Special ping pong event, fired on new hook
+ 'repository', // Repository created
+ ];
+
+ return in_array( $this->event, $administrativeEvents );
+ }
+
+ ///
+ /// Description of the payload
+ ///
+
+ /**
+ * Gets a short textual description of the event.
+ *
+ * @return string
+ */
+ public function getDescription(): string {
+ return $this->analyzerEvent->getDescription();
+ }
+
+ /**
+ * Gets a link to view the event on GitHub.
+ *
+ * @return string The most relevant URL
+ */
+ public function getLink(): string {
+ return $this->analyzerEvent->getLink();
+ }
}
diff --git a/app/Analyzers/ItemGroupMapping.php b/app/Analyzers/ItemGroupMapping.php
--- a/app/Analyzers/ItemGroupMapping.php
+++ b/app/Analyzers/ItemGroupMapping.php
@@ -5,7 +5,8 @@
/**
* Map items (repositories, projects, items, etc.) names to groups
*/
-class ItemGroupMapping {
+class ItemGroupMapping
+{
///
/// Properties
@@ -38,11 +39,11 @@
* @param string $item The item name to compare with the pattern
* @return bool
*/
- public static function doesItemMatch (
+ public static function doesItemMatch(
string $pattern,
string $item
- ) : bool {
- return str_is($pattern, $item);
+ ): bool {
+ return str_contains($pattern, $item);
}
/**
@@ -50,7 +51,8 @@
*
* @return bool
*/
- public function doesItemBelong (string $actualItem) : bool {
+ public function doesItemBelong(string $actualItem): bool
+ {
foreach ($this->items as $candidateItem) {
if (static::doesItemMatch($candidateItem, $actualItem)) {
return true;
@@ -59,5 +61,4 @@
return false;
}
-
}
diff --git a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
--- a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
+++ b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
@@ -6,77 +6,77 @@
class JenkinsPayloadAnalyzer extends BasePayloadAnalyzer {
- /**
- * The name of the service, used to get specific classes and config
- */
- const SERVICE_NAME = "Jenkins";
+ /**
+ * The name of the service, used to get specific classes and config
+ */
+ const SERVICE_NAME = "Jenkins";
- ///
- /// Payload custom properties
- ///
+ ///
+ /// Payload custom properties
+ ///
- /**
- * Gets the name of the item, ie here of the job.
- *
- * @var string
- */
- public function getItemName () : string {
- return $this->payload->name;
- }
+ /**
+ * Gets the name of the item, ie here of the job.
+ *
+ * @var string
+ */
+ public function getItemName(): string {
+ return $this->payload->name;
+ }
- ///
- /// Notify only on failure helper methods
- ///
+ ///
+ /// Notify only on failure helper methods
+ ///
- /**
- * Tries to get build status.
- *
- * @param out string $status
- * @return bool indicates if the build status is defined in the payload
- */
- private function tryGetBuildStatus (string &$status) : bool {
- if (!isset($this->payload->build->status)) {
- return false;
- }
+ /**
+ * Tries to get build status.
+ *
+ * @param out string &$status
+ * @return bool indicates if the build status is defined in the payload
+ */
+ private function tryGetBuildStatus( string &$status ): bool {
+ if ( !isset( $this->payload->build->status ) ) {
+ return false;
+ }
- $status = $this->payload->build->status;
- return true;
- }
+ $status = $this->payload->build->status;
+ return true;
+ }
- /**
- * @return bool
- */
- public function shouldNotifyOnlyOnFailure () : bool {
- return in_array(
- $this->getItemName(),
- $this->configuration->notifyOnlyOnFailure
- );
- }
+ /**
+ * @return bool
+ */
+ public function shouldNotifyOnlyOnFailure(): bool {
+ return in_array(
+ $this->getItemName(),
+ $this->configuration->notifyOnlyOnFailure
+ );
+ }
- /**
- * Determines if the build status is a failure.
- *
- * @return bool
- */
- public function isFailure () : bool {
- $status = "";
+ /**
+ * Determines if the build status is a failure.
+ *
+ * @return bool
+ */
+ public function isFailure(): bool {
+ $status = "";
- if (!$this->tryGetBuildStatus($status)) {
- return false;
- }
+ if ( !$this->tryGetBuildStatus( $status ) ) {
+ return false;
+ }
- return $status === "FAILURE"
- || $status === "ABORTED"
- || $status === "UNSTABLE";
- }
+ return $status === "FAILURE"
+ || $status === "ABORTED"
+ || $status === "UNSTABLE";
+ }
- /**
- * Indicates if we should handle this payload to trigger a notification.
- *
- * @return bool if false, this payload is to be ignored for notifications
- */
- public function shouldNotify () : bool {
- return $this->isFailure() || !$this->shouldNotifyOnlyOnFailure();
- }
+ /**
+ * Indicates if we should handle this payload to trigger a notification.
+ *
+ * @return bool if false, this payload is to be ignored for notifications
+ */
+ public function shouldNotify(): bool {
+ return $this->isFailure() || !$this->shouldNotifyOnlyOnFailure();
+ }
}
diff --git a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php
--- a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php
@@ -6,13 +6,13 @@
class JenkinsPayloadAnalyzerConfiguration extends PayloadAnalyzerConfiguration {
- ///
- /// Public properties
- ///
+ ///
+ /// Public properties
+ ///
- /**
- * @var array
- */
- public $notifyOnlyOnFailure;
+ /**
+ * @var array
+ */
+ public $notifyOnlyOnFailure;
}
diff --git a/app/Analyzers/PayloadAnalyzerConfiguration.php b/app/Analyzers/PayloadAnalyzerConfiguration.php
--- a/app/Analyzers/PayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/PayloadAnalyzerConfiguration.php
@@ -4,71 +4,71 @@
class PayloadAnalyzerConfiguration {
- ///
- /// Private members
- ///
+ ///
+ /// Private members
+ ///
- /**
- * The project this configuration is for
- *
- * @var string
- */
- protected $project;
+ /**
+ * The project this configuration is for
+ *
+ * @var string
+ */
+ protected $project;
- ///
- /// Public properties
- ///
+ ///
+ /// Public properties
+ ///
- /**
- * The group for organization only events
- *
- * @var string
- */
- public $administrativeGroup;
+ /**
+ * The group for organization only events
+ *
+ * @var string
+ */
+ public $administrativeGroup;
- /**
- * The default group to fallback for any event not mapped in another group
- *
- * @var string
- */
- public $defaultGroup;
+ /**
+ * The default group to fallback for any event not mapped in another group
+ *
+ * @var string
+ */
+ public $defaultGroup;
- /**
- * An array of RepositoryGroupMapping objects to match repositories & groups
- *
- * @var \Nasqueron\Notifications\Analyzers\ItemGroupMapping[]
- */
- public $map;
+ /**
+ * An array of RepositoryGroupMapping objects to match repositories & groups
+ *
+ * @var \Nasqueron\Notifications\Analyzers\ItemGroupMapping[]
+ */
+ public $map;
- ///
- /// Constructor
- ///
+ ///
+ /// Constructor
+ ///
- /**
- * Initializes a new instance of the BasePayloadAnalyzerConfiguration class
- *
- * @param string $project The project name this configuration is related to
- */
- public function __construct (string $project) {
- $this->project = $project;
- }
+ /**
+ * Initializes a new instance of the BasePayloadAnalyzerConfiguration class
+ *
+ * @param string $project The project name this configuration is related to
+ */
+ public function __construct( string $project ) {
+ $this->project = $project;
+ }
- ///
- /// Helper methods
- ///
+ ///
+ /// Helper methods
+ ///
- /**
- * Gets the default group
- *
- * @return string the default group, as set in the configuration,
- * or if omitted, the project name as fallback.
- */
- public function getDefaultGroup () : string {
- if (empty($this->defaultGroup)) {
- return strtolower($this->project);
- }
+ /**
+ * Gets the default group
+ *
+ * @return string the default group, as set in the configuration,
+ * or if omitted, the project name as fallback.
+ */
+ public function getDefaultGroup(): string {
+ if ( empty( $this->defaultGroup ) ) {
+ return strtolower( $this->project );
+ }
- return $this->defaultGroup;
- }
+ return $this->defaultGroup;
+ }
}
diff --git a/app/Analyzers/Phabricator/PhabricatorGroupMapping.php b/app/Analyzers/Phabricator/PhabricatorGroupMapping.php
--- a/app/Analyzers/Phabricator/PhabricatorGroupMapping.php
+++ b/app/Analyzers/Phabricator/PhabricatorGroupMapping.php
@@ -6,34 +6,34 @@
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
class PhabricatorGroupMapping extends ItemGroupMapping {
-
- ///
- /// Extra properties
- ///
-
- /**
- * An array of words, each item a string with a word to find in the story.
- *
- * @var array
- */
- public $words = [];
-
- ///
- /// Helper methods to process words
- ///
-
- /**
- * Determines if the specified story belong to this mapping
- *
- * @return bool
- */
- public function doesStoryBelong (PhabricatorStory $story) : bool {
- foreach ($this->words as $word) {
- if (stripos($story->text, $word) !== false) {
- return true;
- }
- }
- return false;
- }
-
+
+ ///
+ /// Extra properties
+ ///
+
+ /**
+ * An array of words, each item a string with a word to find in the story.
+ *
+ * @var array
+ */
+ public $words = [];
+
+ ///
+ /// Helper methods to process words
+ ///
+
+ /**
+ * Determines if the specified story belong to this mapping
+ *
+ * @return bool
+ */
+ public function doesStoryBelong( PhabricatorStory $story ): bool {
+ foreach ( $this->words as $word ) {
+ if ( stripos( $story->text, $word ) !== false ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
diff --git a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
--- a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
@@ -8,70 +8,70 @@
class PhabricatorPayloadAnalyzer extends BasePayloadAnalyzer {
- /**
- * The name of the service, used to get specific classes and config
- */
- const SERVICE_NAME = "Phabricator";
+ /**
+ * The name of the service, used to get specific classes and config
+ */
+ const SERVICE_NAME = "Phabricator";
- ///
- /// Private members
- ///
+ ///
+ /// Private members
+ ///
- /**
- * The story
- * @var PhabricatorStory
- */
- private $story;
+ /**
+ * The story
+ * @var PhabricatorStory
+ */
+ private $story;
- ///
- /// Constructor
- ///
+ ///
+ /// Constructor
+ ///
- /**
- * Creates a new PhabricatorPayloadAnalyzer instance.
- *
- * @param string $project
- * @param PhabricatorStory $story
- */
- public function __construct(string $project, PhabricatorStory $story) {
- $this->project = $project;
- $this->story = $story;
+ /**
+ * Creates a new PhabricatorPayloadAnalyzer instance.
+ *
+ * @param string $project
+ * @param PhabricatorStory $story
+ */
+ public function __construct( string $project, PhabricatorStory $story ) {
+ $this->project = $project;
+ $this->story = $story;
- $this->loadConfiguration();
- }
+ $this->loadConfiguration();
+ }
- ///
- /// Qualification of the story
- ///
+ ///
+ /// Qualification of the story
+ ///
- /**
- * Gets the group for a specific story.
- *
- * @return string the group, central part of the routing key
- */
- public function getGroup () : string {
- // If the payload is about some repository matching a table of
- // symbols, we need to sort it to the right group.
- foreach ($this->configuration->map as $mapping) {
- foreach ($this->story->getProjects() as $project) {
- if ($mapping->doesItemBelong($project)) {
- return $mapping->group;
- }
- }
- }
+ /**
+ * Gets the group for a specific story.
+ *
+ * @return string the group, central part of the routing key
+ */
+ public function getGroup(): string {
+ // If the payload is about some repository matching a table of
+ // symbols, we need to sort it to the right group.
+ foreach ( $this->configuration->map as $mapping ) {
+ foreach ( $this->story->getProjects() as $project ) {
+ if ( $mapping->doesItemBelong( $project ) ) {
+ return $mapping->group;
+ }
+ }
+ }
- // Words
- foreach ($this->configuration->map as $mapping) {
- if ($mapping->doesStoryBelong($this->story)) {
- return $mapping->group;
- }
- }
+ // Words
+ foreach ( $this->configuration->map as $mapping ) {
+ if ( $mapping->doesStoryBelong( $this->story ) ) {
+ return $mapping->group;
+ }
+ }
- // By default, fallback group is the project name or a specified value.
- if (empty($this->configuration->defaultGroup)) {
- return strtolower($this->project);
- }
- return $this->configuration->defaultGroup;
- }
+ // By default, fallback group is the project name or a specified value.
+ if ( empty( $this->configuration->defaultGroup ) ) {
+ return strtolower( $this->project );
+ }
+ return $this->configuration->defaultGroup;
+ }
}
diff --git a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
--- a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
@@ -5,13 +5,13 @@
use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration;
class PhabricatorPayloadAnalyzerConfiguration
- extends PayloadAnalyzerConfiguration {
+ extends PayloadAnalyzerConfiguration {
- /**
- * An array of RepositoryGroupMapping objects to match repositories & groups
- *
- * @var PhabricatorGroupMapping[]
- */
- public $map;
+ /**
+ * An array of RepositoryGroupMapping objects to match repositories & groups
+ *
+ * @var PhabricatorGroupMapping[]
+ */
+ public $map;
}
diff --git a/app/Config/Features.php b/app/Config/Features.php
--- a/app/Config/Features.php
+++ b/app/Config/Features.php
@@ -12,81 +12,81 @@
*/
class Features {
- ///
- /// Feature information
- ///
+ ///
+ /// Feature information
+ ///
- /**
- * Gets the configuration key for the specified feature name.
- *
- * @param string $feature The feature to get the config key
- * @return string The config key
- */
- private static function getFeatureConfigKey (string $feature) : string {
- return 'app.features.' . $feature;
- }
+ /**
+ * Gets the configuration key for the specified feature name.
+ *
+ * @param string $feature The feature to get the config key
+ * @return string The config key
+ */
+ private static function getFeatureConfigKey( string $feature ): string {
+ return 'app.features.' . $feature;
+ }
- /**
- * Determines if the specified feature is enabled.
- *
- * @param string $feature The feature to check in the config
- * @return bool
- */
- public static function isEnabled (string $feature) : bool {
- $key = self::getFeatureConfigKey($feature);
- return Config::has($key) && (bool)Config::get($key);
- }
+ /**
+ * Determines if the specified feature is enabled.
+ *
+ * @param string $feature The feature to check in the config
+ * @return bool
+ */
+ public static function isEnabled( string $feature ): bool {
+ $key = self::getFeatureConfigKey( $feature );
+ return Config::has( $key ) && (bool)Config::get( $key );
+ }
- /**
- * Enables a feature in our current configuration instance.
- *
- * @param string $feature The feature
- */
- public static function enable (string $feature) : void {
- $key = self::getFeatureConfigKey($feature);
- Config::set($key, true);
- }
+ /**
+ * Enables a feature in our current configuration instance.
+ *
+ * @param string $feature The feature
+ */
+ public static function enable( string $feature ): void {
+ $key = self::getFeatureConfigKey( $feature );
+ Config::set( $key, true );
+ }
- /**
- * Disables a feature in our current configuration instance.
- *
- * @param string $feature The feature
- */
- public static function disable (string $feature) : void {
- $key = self::getFeatureConfigKey($feature);
- Config::set($key, false);
- }
+ /**
+ * Disables a feature in our current configuration instance.
+ *
+ * @param string $feature The feature
+ */
+ public static function disable( string $feature ): void {
+ $key = self::getFeatureConfigKey( $feature );
+ Config::set( $key, false );
+ }
- ///
- /// Features lists
- ///
+ ///
+ /// Features lists
+ ///
- /**
- * Gets all the features, with the toggle status.
- */
- public static function getAll () : array {
- return Config::get('app.features');
- }
+ /**
+ * Gets all the features, with the toggle status.
+ */
+ public static function getAll(): array {
+ return Config::get( 'app.features' );
+ }
- /**
- * Lists all the features.
- *
- * @return string[] a list of all features
- */
- public static function getAvailable () : array {
- $features = self::getAll();
- return array_keys($features);
- }
+ /**
+ * Lists all the features.
+ *
+ * @return string[] a list of all features
+ */
+ public static function getAvailable(): array {
+ $features = self::getAll();
+ return array_keys( $features );
+ }
- /**
- * Lists the enabled features.
- *
- * @return string[] a list of enabled features
- */
- public static function getEnabled () : array {
- $features = self::getAll();
- $enabledFeatures = array_filter($features);
- return array_keys($enabledFeatures);
- }
+ /**
+ * Lists the enabled features.
+ *
+ * @return string[] a list of enabled features
+ */
+ public static function getEnabled(): array {
+ $features = self::getAll();
+ $enabledFeatures = array_filter( $features );
+ return array_keys( $enabledFeatures );
+ }
}
diff --git a/app/Config/Reporting/BaseReportEntry.php b/app/Config/Reporting/BaseReportEntry.php
--- a/app/Config/Reporting/BaseReportEntry.php
+++ b/app/Config/Reporting/BaseReportEntry.php
@@ -4,55 +4,56 @@
abstract class BaseReportEntry {
- ///
- /// Format
- ///
-
- public abstract function toArray () : array;
- public abstract function toFancyArray () : array;
-
- ///
- /// Format helper methods
- ///
-
- /**
- * Returns a fancy string for reports.
- *
- * @param string $string The source string
- * @param string $emptyStringGlyph The glyph to use if the string is empty
- * @return string
- */
- public static function fancyString (
- string $string,
- string $emptyStringGlyph
- ) : string {
- if ($string === "") {
- return $emptyStringGlyph;
- }
-
- return $string;
- }
-
- /**
- * Returns a fancy representation from a boolean for reports.
- *
- * @param bool $value The source value
- * @param string $truthyStringGlyph The glyph to use if the value is true
- * @param string $falsyStringGlyph The glyph to use if the value is false
- * [facultative, by default an empty string]
- *
- * @return string The relevant glyph
- */
- public static function fancyBool (
- bool $value,
- string $truthyStringGlyph,
- string $falsyStringGlyph = ''
- ) : string {
- if ($value) {
- return $truthyStringGlyph;
- }
-
- return $falsyStringGlyph;
- }
+ ///
+ /// Format
+ ///
+
+ abstract public function toArray(): array;
+
+ abstract public function toFancyArray(): array;
+
+ ///
+ /// Format helper methods
+ ///
+
+ /**
+ * Returns a fancy string for reports.
+ *
+ * @param string $string The source string
+ * @param string $emptyStringGlyph The glyph to use if the string is empty
+ * @return string
+ */
+ public static function fancyString(
+ string $string,
+ string $emptyStringGlyph
+ ): string {
+ if ( $string === "" ) {
+ return $emptyStringGlyph;
+ }
+
+ return $string;
+ }
+
+ /**
+ * Returns a fancy representation from a boolean for reports.
+ *
+ * @param bool $value The source value
+ * @param string $truthyStringGlyph The glyph to use if the value is true
+ * @param string $falsyStringGlyph The glyph to use if the value is false
+ * [facultative, by default an empty string]
+ *
+ * @return string The relevant glyph
+ */
+ public static function fancyBool(
+ bool $value,
+ string $truthyStringGlyph,
+ string $falsyStringGlyph = ''
+ ): string {
+ if ( $value ) {
+ return $truthyStringGlyph;
+ }
+
+ return $falsyStringGlyph;
+ }
}
diff --git a/app/Config/Reporting/ConfigReport.php b/app/Config/Reporting/ConfigReport.php
--- a/app/Config/Reporting/ConfigReport.php
+++ b/app/Config/Reporting/ConfigReport.php
@@ -2,83 +2,82 @@
namespace Nasqueron\Notifications\Config\Reporting;
-use Nasqueron\Notifications\Config\Features;
-
use Config;
+use Nasqueron\Notifications\Config\Features;
use Services;
class ConfigReport {
- ///
- /// Public properties
- ///
-
- /**
- * @var string[]
- */
- public $gates;
-
- /**
- * @var FeatureReportEntry[]
- */
- public $features;
-
- /**
- * @var ServiceReportEntry[]
- */
- public $services;
-
- ///
- /// Public constructor
- ///
-
- public function __construct () {
- $this->gates = $this->queryGates();
- $this->features = $this->queryFeatures();
- $this->services = $this->queryServices();
- }
-
- ///
- /// Report builder
- ///
-
- /**
- * Queries information about the features enabled from the configuration.
- *
- * @return string[]
- */
- protected function queryGates () : array {
- return Config::get('gate.controllers');
- }
-
- /**
- * Queries information about the features enabled from the configuration.
- *
- * @return FeatureReportEntry[]
- */
- protected function queryFeatures () : array {
- $features = [];
-
- foreach (Features::getAll() as $feature => $enabled) {
- $features[] = new FeatureReportEntry($feature, $enabled);
- }
-
- return $features;
- }
-
- /**
- * Queries information about services described in credentials.json.
- *
- * @return ServiceReportEntry[]
- */
- protected function queryServices () : array {
- $services = [];
-
- foreach (Services::get() as $service) {
- $services[] = new ServiceReportEntry($service);
- }
-
- return $services;
- }
+ ///
+ /// Public properties
+ ///
+
+ /**
+ * @var string[]
+ */
+ public $gates;
+
+ /**
+ * @var FeatureReportEntry[]
+ */
+ public $features;
+
+ /**
+ * @var ServiceReportEntry[]
+ */
+ public $services;
+
+ ///
+ /// Public constructor
+ ///
+
+ public function __construct() {
+ $this->gates = $this->queryGates();
+ $this->features = $this->queryFeatures();
+ $this->services = $this->queryServices();
+ }
+
+ ///
+ /// Report builder
+ ///
+
+ /**
+ * Queries information about the features enabled from the configuration.
+ *
+ * @return string[]
+ */
+ protected function queryGates(): array {
+ return Config::get( 'gate.controllers' );
+ }
+
+ /**
+ * Queries information about the features enabled from the configuration.
+ *
+ * @return FeatureReportEntry[]
+ */
+ protected function queryFeatures(): array {
+ $features = [];
+
+ foreach ( Features::getAll() as $feature => $enabled ) {
+ $features[] = new FeatureReportEntry( $feature, $enabled );
+ }
+
+ return $features;
+ }
+
+ /**
+ * Queries information about services described in credentials.json.
+ *
+ * @return ServiceReportEntry[]
+ */
+ protected function queryServices(): array {
+ $services = [];
+
+ foreach ( Services::get() as $service ) {
+ $services[] = new ServiceReportEntry( $service );
+ }
+
+ return $services;
+ }
}
diff --git a/app/Config/Reporting/FeatureReportEntry.php b/app/Config/Reporting/FeatureReportEntry.php
--- a/app/Config/Reporting/FeatureReportEntry.php
+++ b/app/Config/Reporting/FeatureReportEntry.php
@@ -4,61 +4,61 @@
final class FeatureReportEntry extends BaseReportEntry {
- ///
- /// Public properties
- ///
+ ///
+ /// Public properties
+ ///
- /**
- * @var string
- */
- public $name;
+ /**
+ * @var string
+ */
+ public $name;
- /**
- * @var bool
- */
- public $enabled;
+ /**
+ * @var bool
+ */
+ public $enabled;
- ///
- /// Constructor
- ///
+ ///
+ /// Constructor
+ ///
- /**
- * Initializes a new instance of the FeatureReportEntry class.
- *
- * @var name The feature name
- * @var bool If the feature enabled, true. Otherwise, false.
- */
- public function __construct (string $name, bool $enabled) {
- $this->name = $name;
- $this->enabled = $enabled;
- }
+ /**
+ * Initializes a new instance of the FeatureReportEntry class.
+ *
+ * @var name The feature name
+ * @var bool If the feature enabled, true. Otherwise, false.
+ */
+ public function __construct( string $name, bool $enabled ) {
+ $this->name = $name;
+ $this->enabled = $enabled;
+ }
- ///
- /// Format
- ///
+ ///
+ /// Format
+ ///
- /**
- * Gets the entry as an array.
- *
- * @return string[]
- */
- public function toArray () : array {
- return [
- $this->name,
- (string)$this->enabled,
- ];
- }
+ /**
+ * Gets the entry as an array.
+ *
+ * @return string[]
+ */
+ public function toArray(): array {
+ return [
+ $this->name,
+ (string)$this->enabled,
+ ];
+ }
- /**
- * Gets the entry as an array. Formats empty string.
- *
- * @return string[]
- */
- public function toFancyArray () : array {
- return [
- $this->name,
- self::fancyBool($this->enabled, '✓'),
- ];
- }
+ /**
+ * Gets the entry as an array. Formats empty string.
+ *
+ * @return string[]
+ */
+ public function toFancyArray(): array {
+ return [
+ $this->name,
+ self::fancyBool( $this->enabled, '✓' ),
+ ];
+ }
}
diff --git a/app/Config/Reporting/ServiceReportEntry.php b/app/Config/Reporting/ServiceReportEntry.php
--- a/app/Config/Reporting/ServiceReportEntry.php
+++ b/app/Config/Reporting/ServiceReportEntry.php
@@ -8,122 +8,122 @@
final class ServiceReportEntry extends BaseReportEntry {
- ///
- /// Private members
- ///
-
- /**
- * @var Service
- */
- private $service;
-
- ///
- /// Public properties
- ///
-
- /**
- * @var string
- */
- public $gate;
-
- /**
- * @var string
- */
- public $door;
-
- /**
- * @var string
- */
- public $instance;
-
- /**
- * @var string
- */
- public $status = "";
-
- ///
- /// Constructor
- ///
-
- public function __construct (Service $service) {
- $this->service = $service;
- $this->query();
- }
-
- ///
- /// Report builder
- ///
-
- /**
- * Queries the service to fill public properties.
- */
- protected function query () : void {
- // Direct properties
- $this->gate = $this->service->gate;
- $this->door = $this->service->door;
- $this->instance = (string)$this->service->instance;
-
- // Properties to query with business logic
- $this->status = $this->getServiceStatus();
- }
-
- /**
- * @return string An issue to fix, or an empty string if all looks good.
- */
- protected function getServiceStatus () : string {
- if ($this->isPhabricatorServiceWithNotCachedProjectsMap()) {
- return "Projects map not cached.";
- }
-
- return "";
- }
-
- /**
- * Determines if the service matches the following issue to report:
- * - service is Phabricator
- * - instance doesn't have the projects' name/PHID map in cache
- *
- * @return bool
- */
- protected function isPhabricatorServiceWithNotCachedProjectsMap () : bool {
- if ($this->service->gate !== 'Phabricator') {
- return false;
- }
-
- $map = ProjectsMap::fetch($this->service->door);
- return !$map->isCached();
- }
-
- ///
- /// Format
- ///
-
- /**
- * Gets the entry as an array. Formats empty string.
- *
- * @return string[]
- */
- public function toArray () : array {
- return [
- $this->gate,
- $this->door,
- $this->instance,
- $this->status,
- ];
- }
-
- /**
- * Gets the entry as an array. Formats empty string.
- *
- * @return string[]
- */
- public function toFancyArray () : array {
- return [
- $this->gate,
- $this->door,
- self::fancyString($this->instance, 'ø'),
- self::fancyString($this->status, '✓'),
- ];
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * @var Service
+ */
+ private $service;
+
+ ///
+ /// Public properties
+ ///
+
+ /**
+ * @var string
+ */
+ public $gate;
+
+ /**
+ * @var string
+ */
+ public $door;
+
+ /**
+ * @var string
+ */
+ public $instance;
+
+ /**
+ * @var string
+ */
+ public $status = "";
+
+ ///
+ /// Constructor
+ ///
+
+ public function __construct( Service $service ) {
+ $this->service = $service;
+ $this->query();
+ }
+
+ ///
+ /// Report builder
+ ///
+
+ /**
+ * Queries the service to fill public properties.
+ */
+ protected function query(): void {
+ // Direct properties
+ $this->gate = $this->service->gate;
+ $this->door = $this->service->door;
+ $this->instance = (string)$this->service->instance;
+
+ // Properties to query with business logic
+ $this->status = $this->getServiceStatus();
+ }
+
+ /**
+ * @return string An issue to fix, or an empty string if all looks good.
+ */
+ protected function getServiceStatus(): string {
+ if ( $this->isPhabricatorServiceWithNotCachedProjectsMap() ) {
+ return "Projects map not cached.";
+ }
+
+ return "";
+ }
+
+ /**
+ * Determines if the service matches the following issue to report:
+ * - service is Phabricator
+ * - instance doesn't have the projects' name/PHID map in cache
+ *
+ * @return bool
+ */
+ protected function isPhabricatorServiceWithNotCachedProjectsMap(): bool {
+ if ( $this->service->gate !== 'Phabricator' ) {
+ return false;
+ }
+
+ $map = ProjectsMap::fetch( $this->service->door );
+ return !$map->isCached();
+ }
+
+ ///
+ /// Format
+ ///
+
+ /**
+ * Gets the entry as an array. Formats empty string.
+ *
+ * @return string[]
+ */
+ public function toArray(): array {
+ return [
+ $this->gate,
+ $this->door,
+ $this->instance,
+ $this->status,
+ ];
+ }
+
+ /**
+ * Gets the entry as an array. Formats empty string.
+ *
+ * @return string[]
+ */
+ public function toFancyArray(): array {
+ return [
+ $this->gate,
+ $this->door,
+ self::fancyString( $this->instance, 'ø' ),
+ self::fancyString( $this->status, '✓' ),
+ ];
+ }
}
diff --git a/app/Config/Services/Service.php b/app/Config/Services/Service.php
--- a/app/Config/Services/Service.php
+++ b/app/Config/Services/Service.php
@@ -3,36 +3,36 @@
namespace Nasqueron\Notifications\Config\Services;
class Service {
- /**
- * @var string
- */
- public $gate;
+ /**
+ * @var string
+ */
+ public $gate;
- /**
- * @var string
- */
- public $door;
+ /**
+ * @var string
+ */
+ public $door;
- /**
- * @var string
- */
- public $instance;
+ /**
+ * @var string
+ */
+ public $instance;
- /**
- * @var string
- */
- public $secret;
+ /**
+ * @var string
+ */
+ public $secret;
- /**
- * Gets instance name
- *
- * @return string The instance name or "ø" if omitted
- */
- public function getInstanceName () : string {
- if (!isset($this->instance)) {
- return "ø";
- }
+ /**
+ * Gets instance name
+ *
+ * @return string The instance name or "ø" if omitted
+ */
+ public function getInstanceName(): string {
+ if ( !isset( $this->instance ) ) {
+ return "ø";
+ }
- return $this->instance;
- }
+ return $this->instance;
+ }
}
diff --git a/app/Config/Services/Services.php b/app/Config/Services/Services.php
--- a/app/Config/Services/Services.php
+++ b/app/Config/Services/Services.php
@@ -6,102 +6,102 @@
class Services {
- ///
- /// Properties
- ///
-
- /**
- * @var Service[]
- */
- public $services = [];
-
- ///
- /// Constructors
- ///
-
- /**
- * @param string $file The JSON file to deserialize
- * @return Services The deserialized instance
- */
- public static function loadFromJson (string $file) : Services {
- $data = json_decode(Storage::get($file));
- $mapper = new \JsonMapper();
-
- return $mapper->map($data, new self());
- }
-
- ///
- /// Methods to get a list of services
- ///
-
- /**
- * Gets the services found in credentials.json configuration file.
- *
- * @return Service[]
- */
- public function get () {
- return $this->services;
- }
-
- /**
- * Gets all the services for a specific gate.
- *
- * @param string $gate The gate (e.g. GitHub)
- * @return Service[]
- */
- public function getForGate (string $gate) : array {
- $services = [];
-
- foreach ($this->services as $service) {
- if ($service->gate === $gate) {
- $services[] = $service;
- }
- }
-
- return $services;
- }
-
- ///
- /// Methods to find a service matching criteria
- ///
-
- /**
- * Gets the service for a specific gate and door
- *
- * @param string $gate The gate (e.g. GitHub)
- * @param string $door The door (e.g. Nasqueron)
- * @return Service|null The service information is found; otherwise, null.
- */
- public function findServiceByDoor (string $gate, string $door) : ?Service {
- foreach ($this->services as $service) {
- if ($service->gate === $gate && $service->door === $door) {
- return $service;
- }
- }
-
- return null;
- }
-
- /**
- * Finds a service for a specific gate, property and value
- *
- * @param string $gate The gate (e.g. Phabricator)
- * @param string $property The property to check (e.g. instance)
- * @param mixed $value The property value to find
- * (e.g. 'http://devcentral.nasqueron.org')
- * @return Service|null The service information is found; otherwise, null.
- */
- public function findServiceByProperty (
- string $gate,
- string $property,
- $value
- ) : ?Service {
- foreach ($this->services as $service) {
- if ($service->gate === $gate && $service->$property === $value) {
- return $service;
- }
- }
-
- return null;
- }
+ ///
+ /// Properties
+ ///
+
+ /**
+ * @var Service[]
+ */
+ public $services = [];
+
+ ///
+ /// Constructors
+ ///
+
+ /**
+ * @param string $file The JSON file to deserialize
+ * @return Services The deserialized instance
+ */
+ public static function loadFromJson( string $file ): Services {
+ $data = json_decode( Storage::get( $file ) );
+ $mapper = new \JsonMapper();
+
+ return $mapper->map( $data, new self() );
+ }
+
+ ///
+ /// Methods to get a list of services
+ ///
+
+ /**
+ * Gets the services found in credentials.json configuration file.
+ *
+ * @return Service[]
+ */
+ public function get() {
+ return $this->services;
+ }
+
+ /**
+ * Gets all the services for a specific gate.
+ *
+ * @param string $gate The gate (e.g. GitHub)
+ * @return Service[]
+ */
+ public function getForGate( string $gate ): array {
+ $services = [];
+
+ foreach ( $this->services as $service ) {
+ if ( $service->gate === $gate ) {
+ $services[] = $service;
+ }
+ }
+
+ return $services;
+ }
+
+ ///
+ /// Methods to find a service matching criteria
+ ///
+
+ /**
+ * Gets the service for a specific gate and door
+ *
+ * @param string $gate The gate (e.g. GitHub)
+ * @param string $door The door (e.g. Nasqueron)
+ * @return Service|null The service information is found; otherwise, null.
+ */
+ public function findServiceByDoor( string $gate, string $door ): ?Service {
+ foreach ( $this->services as $service ) {
+ if ( $service->gate === $gate && $service->door === $door ) {
+ return $service;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Finds a service for a specific gate, property and value
+ *
+ * @param string $gate The gate (e.g. Phabricator)
+ * @param string $property The property to check (e.g. instance)
+ * @param mixed $value The property value to find
+ * (e.g. 'http://devcentral.nasqueron.org')
+ * @return Service|null The service information is found; otherwise, null.
+ */
+ public function findServiceByProperty(
+ string $gate,
+ string $property,
+ $value
+ ): ?Service {
+ foreach ( $this->services as $service ) {
+ if ( $service->gate === $gate && $service->$property === $value ) {
+ return $service;
+ }
+ }
+
+ return null;
+ }
}
diff --git a/app/Console/Commands/ConfigShow.php b/app/Console/Commands/ConfigShow.php
--- a/app/Console/Commands/ConfigShow.php
+++ b/app/Console/Commands/ConfigShow.php
@@ -8,98 +8,98 @@
class ConfigShow extends Command {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'config:show';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Show notifications center configuration';
-
- /**
- * @var \Nasqueron\Notifications\Config\Reporting\ConfigReport
- */
- private $report;
-
- ///
- /// Prepare information tables
- ///
-
- /**
- * Gets the services (defined in credentials.json) as table rows.
- *
- * @return array
- */
- protected function getServicesTableRows () : array {
- $rows = [];
-
- foreach ($this->report->services as $service) {
- $rows[] = $service->toFancyArray();
- }
-
- return $rows;
- }
-
- /**
- * Gets features as table rows
- *
- * @return array
- */
- protected function getFeaturesTableRows () : array {
- $rows = [];
-
- foreach ($this->report->features as $feature) {
- $rows[] = $feature->toFancyArray();
- }
-
- return $rows;
- }
-
- ///
- /// Handle the command
- ///
-
- /**
- * Executes the console command.
- */
- public function handle () : void {
- $this->prepareReport();
-
- $this->printGates();
- $this->printFeatures();
- $this->printServices();
- }
-
- protected final function prepareReport() : void {
- $this->report = new ConfigReport();
- }
-
- protected final function printGates () : void {
- $this->info("Gates:\n");
- foreach ($this->report->gates as $gate) {
- $this->line('- ' . $gate);
- }
- }
-
- protected final function printFeatures () : void {
- $this->info("\nFeatures:\n");
- $this->table(
- ['Feature', 'Enabled'],
- $this->getFeaturesTableRows()
- );
- }
-
- protected final function printServices () : void {
- $this->info("\nServices declared in credentials:\n");
- $this->table(
- ['Gate', 'Door', 'Instance', 'Status'],
- $this->getServicesTableRows()
- );
- }
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'config:show';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Show notifications center configuration';
+
+ /**
+ * @var \Nasqueron\Notifications\Config\Reporting\ConfigReport
+ */
+ private $report;
+
+ ///
+ /// Prepare information tables
+ ///
+
+ /**
+ * Gets the services (defined in credentials.json) as table rows.
+ *
+ * @return array
+ */
+ protected function getServicesTableRows(): array {
+ $rows = [];
+
+ foreach ( $this->report->services as $service ) {
+ $rows[] = $service->toFancyArray();
+ }
+
+ return $rows;
+ }
+
+ /**
+ * Gets features as table rows
+ *
+ * @return array
+ */
+ protected function getFeaturesTableRows(): array {
+ $rows = [];
+
+ foreach ( $this->report->features as $feature ) {
+ $rows[] = $feature->toFancyArray();
+ }
+
+ return $rows;
+ }
+
+ ///
+ /// Handle the command
+ ///
+
+ /**
+ * Executes the console command.
+ */
+ public function handle(): void {
+ $this->prepareReport();
+
+ $this->printGates();
+ $this->printFeatures();
+ $this->printServices();
+ }
+
+ final protected function prepareReport(): void {
+ $this->report = new ConfigReport();
+ }
+
+ final protected function printGates(): void {
+ $this->info( "Gates:\n" );
+ foreach ( $this->report->gates as $gate ) {
+ $this->line( '- ' . $gate );
+ }
+ }
+
+ final protected function printFeatures(): void {
+ $this->info( "\nFeatures:\n" );
+ $this->table(
+ [ 'Feature', 'Enabled' ],
+ $this->getFeaturesTableRows()
+ );
+ }
+
+ final protected function printServices(): void {
+ $this->info( "\nServices declared in credentials:\n" );
+ $this->table(
+ [ 'Gate', 'Door', 'Instance', 'Status' ],
+ $this->getServicesTableRows()
+ );
+ }
}
diff --git a/app/Console/Commands/ConfigValidate.php b/app/Console/Commands/ConfigValidate.php
--- a/app/Console/Commands/ConfigValidate.php
+++ b/app/Console/Commands/ConfigValidate.php
@@ -2,53 +2,52 @@
namespace Nasqueron\Notifications\Console\Commands;
+use App;
use Illuminate\Console\Command;
use Illuminate\Filesystem\FilesystemAdapter;
-use App;
-
class ConfigValidate extends Command {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'config:validate';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Validates JSON configuration files';
-
- private function getFS () : FilesystemAdapter {
- return App::make('filesystem')->disk('local');
- }
-
- private function getConfigFiles () : array {
- return array_filter(
- $this->getFS()->allFiles(),
-
- // Filters *.json
- function ($file) : bool {
- return substr($file, -5) === ".json";
- }
- );
- }
-
- /**
- * Executes the console command.
- */
- public function handle() : void {
- $files = $this->getConfigFiles();
-
- foreach ($files as $file) {
- $content = $this->getFS()->get($file);
- if (json_decode($content) === null) {
- $this->line("$file — " . json_last_error_msg());
- }
- }
- }
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'config:validate';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Validates JSON configuration files';
+
+ private function getFS(): FilesystemAdapter {
+ return App::make( 'filesystem' )->disk( 'local' );
+ }
+
+ private function getConfigFiles(): array {
+ return array_filter(
+ $this->getFS()->allFiles(),
+
+ // Filters *.json
+ static function ( $file ): bool {
+ return substr( $file, -5 ) === ".json";
+ }
+ );
+ }
+
+ /**
+ * Executes the console command.
+ */
+ public function handle(): void {
+ $files = $this->getConfigFiles();
+
+ foreach ( $files as $file ) {
+ $content = $this->getFS()->get( $file );
+ if ( json_decode( $content ) === null ) {
+ $this->line( "$file — " . json_last_error_msg() );
+ }
+ }
+ }
}
diff --git a/app/Console/Commands/Inspire.php b/app/Console/Commands/Inspire.php
--- a/app/Console/Commands/Inspire.php
+++ b/app/Console/Commands/Inspire.php
@@ -6,24 +6,24 @@
use Illuminate\Foundation\Inspiring;
class Inspire extends Command {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'inspire';
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'inspire';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Display an inspiring quote';
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Display an inspiring quote';
- /**
- * Executes the console command.
- */
- public function handle() : void {
- $this->comment(PHP_EOL . Inspiring::quote() . PHP_EOL);
- }
+ /**
+ * Executes the console command.
+ */
+ public function handle(): void {
+ $this->comment( PHP_EOL . Inspiring::quote() . PHP_EOL );
+ }
}
diff --git a/app/Console/Commands/NotificationsPayload.php b/app/Console/Commands/NotificationsPayload.php
--- a/app/Console/Commands/NotificationsPayload.php
+++ b/app/Console/Commands/NotificationsPayload.php
@@ -2,224 +2,221 @@
namespace Nasqueron\Notifications\Console\Commands;
-use Nasqueron\Notifications\Notifications\Notification;
-use Nasqueron\Notifications\Phabricator\PhabricatorStory;
-
use Illuminate\Console\Command;
-
use InvalidArgumentException;
+use Nasqueron\Notifications\Notifications\Notification;
+use Nasqueron\Notifications\Phabricator\PhabricatorStory;
use ReflectionClass;
class NotificationsPayload extends Command {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'notifications:payload {service} {payload} {args*}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = <<<'TXT'
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'notifications:payload {service} {payload} {args*}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = <<<'TXT'
Gets a notification payload from a service payload
TXT;
-
- /**
- * The service to handle a payload for.
- *
- * @var string
- */
- private $service;
-
- /**
- * The payload.
- *
- * @var string
- */
- private $payload;
-
- /**
- * The parameters to pass to the notifications class constructor.
- *
- * An array with arguments' names as keys, arguments' values as values.
- *
- * @var array
- */
- private $constructor;
-
- /**
- * Executes the console command.
- */
- public function handle() : void {
- if ($this->parseArguments()) {
- $this->printNotification();
- }
- }
-
- /**
- * Parses arguments passed to the command.
- *
- * @return bool true if arguments looks good; otherwise, false.
- */
- private function parseArguments () : bool {
- try {
- $this->parseService();
- $this->parsePayload();
- $this->parseConstructorParameters();
- } catch (InvalidArgumentException $ex) {
- $this->error($ex->getMessage());
- return false;
- }
-
- return true;
- }
-
- /**
- * Parses service argument.
- *
- * Fills it to the service property.
- *
- * @throws InvalidArgumentException when a notification class can't be
- * found for the requested service.
- */
- private function parseService () : void {
- $this->service = $this->argument('service');
-
- if (!class_exists($this->getNotificationClass())) {
- throw new InvalidArgumentException(
- "Unknown service: $this->service"
- );
- }
- }
-
- /**
- * Parses path to the payload argument.
- *
- * Fills the content of the file to the payload property.
- *
- * @throws InvalidArgumentException when payload file is not found.
- */
- private function parsePayload () : void {
- $payloadFile = $this->argument('payload');
-
- if (!file_exists($payloadFile)) {
- throw new InvalidArgumentException("File not found: $payloadFile");
- }
-
- $this->payload = file_get_contents($payloadFile);
- }
-
- /**
- * Parses all the extra arguments and sets the constructor property
- * as an array of constructor arguments.
- *
- * @throws InvalidArgumentException on wrong arguments count.
- */
- private function parseConstructorParameters () : void {
- $keys = $this->getNotificationConstructorParameters();
-
- $values = $this->argument('args');
- $values['payload'] = $this->payload;
-
- $this->constructor = self::argumentsArrayCombine($keys, $values);
- $this->constructor['payload'] = $this->formatPayload();
- }
-
- /**
- * Formats payload to pass to constructor
- *
- * @return PhabricatorStory|stdClass A deserialization of the payload
- */
- private function formatPayload() {
- if ($this->service === "Phabricator") {
- $project = $this->constructor['project'];
- return PhabricatorStory::loadFromJson($project, $this->payload);
- }
-
- return json_decode($this->payload);
- }
-
- /**
- * Creates an array by using one array for keys and another for its values.
- *
- * @param array $keys
- * @param array $values
- * @return array
- *
- * @throws InvalidArgumentException when keys and values counts don't match
- */
- public static function argumentsArrayCombine (
- array $keys, array $values
- ) : array {
- $countKeys = count($keys);
- $countValues = count($values);
-
- if ($countKeys != $countValues) {
- throw new InvalidArgumentException(<<<MSG
+ /**
+ * The service to handle a payload for.
+ *
+ * @var string
+ */
+ private $service;
+
+ /**
+ * The payload.
+ *
+ * @var string
+ */
+ private $payload;
+
+ /**
+ * The parameters to pass to the notifications class constructor.
+ *
+ * An array with arguments' names as keys, arguments' values as values.
+ *
+ * @var array
+ */
+ private $constructor;
+
+ /**
+ * Executes the console command.
+ */
+ public function handle(): void {
+ if ( $this->parseArguments() ) {
+ $this->printNotification();
+ }
+ }
+
+ /**
+ * Parses arguments passed to the command.
+ *
+ * @return bool true if arguments looks good; otherwise, false.
+ */
+ private function parseArguments(): bool {
+ try {
+ $this->parseService();
+ $this->parsePayload();
+ $this->parseConstructorParameters();
+ } catch ( InvalidArgumentException $ex ) {
+ $this->error( $ex->getMessage() );
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Parses service argument.
+ *
+ * Fills it to the service property.
+ *
+ * @throws InvalidArgumentException when a notification class can't be
+ * found for the requested service.
+ */
+ private function parseService(): void {
+ $this->service = $this->argument( 'service' );
+
+ if ( !class_exists( $this->getNotificationClass() ) ) {
+ throw new InvalidArgumentException(
+ "Unknown service: $this->service"
+ );
+ }
+ }
+
+ /**
+ * Parses path to the payload argument.
+ *
+ * Fills the content of the file to the payload property.
+ *
+ * @throws InvalidArgumentException when payload file is not found.
+ */
+ private function parsePayload(): void {
+ $payloadFile = $this->argument( 'payload' );
+
+ if ( !file_exists( $payloadFile ) ) {
+ throw new InvalidArgumentException( "File not found: $payloadFile" );
+ }
+
+ $this->payload = file_get_contents( $payloadFile );
+ }
+
+ /**
+ * Parses all the extra arguments and sets the constructor property
+ * as an array of constructor arguments.
+ *
+ * @throws InvalidArgumentException on wrong arguments count.
+ */
+ private function parseConstructorParameters(): void {
+ $keys = $this->getNotificationConstructorParameters();
+
+ $values = $this->argument( 'args' );
+ $values['payload'] = $this->payload;
+
+ $this->constructor = self::argumentsArrayCombine( $keys, $values );
+ $this->constructor['payload'] = $this->formatPayload();
+ }
+
+ /**
+ * Formats payload to pass to constructor
+ *
+ * @return PhabricatorStory|stdClass A deserialization of the payload
+ */
+ private function formatPayload() {
+ if ( $this->service === "Phabricator" ) {
+ $project = $this->constructor['project'];
+ return PhabricatorStory::loadFromJson( $project, $this->payload );
+ }
+
+ return json_decode( $this->payload );
+ }
+
+ /**
+ * Creates an array by using one array for keys and another for its values.
+ *
+ * @param array $keys
+ * @param array $values
+ * @return array
+ *
+ * @throws InvalidArgumentException when keys and values counts don't match
+ */
+ public static function argumentsArrayCombine(
+ array $keys, array $values
+ ): array {
+ $countKeys = count( $keys );
+ $countValues = count( $values );
+
+ if ( $countKeys != $countValues ) {
+ throw new InvalidArgumentException( <<<MSG
Number of arguments mismatch: got $countValues but expected $countKeys.
MSG
- );
- }
-
- return array_combine($keys, $values);
- }
-
- /**
- * Initializes a new instance of the relevant notification class,
- * with the arguments given in the constructor property.
- *
- * @return \Nasqueron\Notifications\Notifications\Notification
- */
- private function getNotification () : Notification {
- $class = $this->getNotificationClass();
- $args = array_values($this->constructor);
- return new $class(...$args);
- }
-
- /**
- * Gets the notification in JSON format.
- *
- * @return string
- */
- private function formatNotification () : string {
- return json_encode($this->getNotification(), JSON_PRETTY_PRINT);
- }
-
- /**
- * Prints the notification for the service, payload and specified arguments.
- */
- private function printNotification () : void {
- $this->line($this->formatNotification());
- }
-
- /**
- * Gets the notification class for the specified service.
- *
- * @return string
- */
- private function getNotificationClass () : string {
- $namespace = "Nasqueron\Notifications\Notifications\\";
- return $namespace . $this->service . "Notification";
- }
-
- /**
- * Gets an array with the parameters to pass to the constructor
- * of the notification class for the specified service.
- *
- * @return array
- */
- private function getNotificationConstructorParameters () : array {
- $parameters = [];
-
- $class = new ReflectionClass($this->getNotificationClass());
- foreach ($class->getConstructor()->getParameters() as $parameter) {
- $parameters[] = $parameter->getName();
- }
-
- return $parameters;
- }
+ );
+ }
+
+ return array_combine( $keys, $values );
+ }
+
+ /**
+ * Initializes a new instance of the relevant notification class,
+ * with the arguments given in the constructor property.
+ *
+ * @return \Nasqueron\Notifications\Notifications\Notification
+ */
+ private function getNotification(): Notification {
+ $class = $this->getNotificationClass();
+ $args = array_values( $this->constructor );
+ return new $class( ...$args );
+ }
+
+ /**
+ * Gets the notification in JSON format.
+ *
+ * @return string
+ */
+ private function formatNotification(): string {
+ return json_encode( $this->getNotification(), JSON_PRETTY_PRINT );
+ }
+
+ /**
+ * Prints the notification for the service, payload and specified arguments.
+ */
+ private function printNotification(): void {
+ $this->line( $this->formatNotification() );
+ }
+
+ /**
+ * Gets the notification class for the specified service.
+ *
+ * @return string
+ */
+ private function getNotificationClass(): string {
+ $namespace = "Nasqueron\Notifications\Notifications\\";
+ return $namespace . $this->service . "Notification";
+ }
+
+ /**
+ * Gets an array with the parameters to pass to the constructor
+ * of the notification class for the specified service.
+ *
+ * @return array
+ */
+ private function getNotificationConstructorParameters(): array {
+ $parameters = [];
+
+ $class = new ReflectionClass( $this->getNotificationClass() );
+ foreach ( $class->getConstructor()->getParameters() as $parameter ) {
+ $parameters[] = $parameter->getName();
+ }
+
+ return $parameters;
+ }
}
diff --git a/app/Console/Commands/PhabricatorProjectsMap.php b/app/Console/Commands/PhabricatorProjectsMap.php
--- a/app/Console/Commands/PhabricatorProjectsMap.php
+++ b/app/Console/Commands/PhabricatorProjectsMap.php
@@ -8,34 +8,34 @@
use Services;
class PhabricatorProjectsMap extends Command {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'phabricator:projectsmap';
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'phabricator:projectsmap';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = <<<'TXT'
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = <<<'TXT'
Regenerate the projects map for each Phabricator instances
TXT;
- /**
- * Executes the console command.
- */
- public function handle() : void {
- foreach (Services::getForGate('Phabricator') as $service) {
- $this->info("Querying projects map for " . $service->instance);
- $map = ProjectsMap::fetch($service->door);
- $map->saveToCache();
- $this->table(
- ['PHID', 'Project name'],
- $map->toArray()
- );
- }
- }
+ /**
+ * Executes the console command.
+ */
+ public function handle(): void {
+ foreach ( Services::getForGate( 'Phabricator' ) as $service ) {
+ $this->info( "Querying projects map for " . $service->instance );
+ $map = ProjectsMap::fetch( $service->door );
+ $map->saveToCache();
+ $this->table(
+ [ 'PHID', 'Project name' ],
+ $map->toArray()
+ );
+ }
+ }
}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -8,61 +8,61 @@
class Kernel extends ConsoleKernel {
- /**
- * The Artisan commands provided by your application.
- *
- * @var string[]
- */
- protected $commands = [
- \Nasqueron\Notifications\Console\Commands\ConfigShow::class,
- \Nasqueron\Notifications\Console\Commands\ConfigValidate::class,
- \Nasqueron\Notifications\Console\Commands\Inspire::class,
- \Nasqueron\Notifications\Console\Commands\NotificationsPayload::class,
- \Nasqueron\Notifications\Console\Commands\PhabricatorProjectsMap::class,
- ];
+ /**
+ * The Artisan commands provided by your application.
+ *
+ * @var string[]
+ */
+ protected $commands = [
+ \Nasqueron\Notifications\Console\Commands\ConfigShow::class,
+ \Nasqueron\Notifications\Console\Commands\ConfigValidate::class,
+ \Nasqueron\Notifications\Console\Commands\Inspire::class,
+ \Nasqueron\Notifications\Console\Commands\NotificationsPayload::class,
+ \Nasqueron\Notifications\Console\Commands\PhabricatorProjectsMap::class,
+ ];
- /**
- * Define the application's command schedule.
- *
- * @param \Illuminate\Console\Scheduling\Schedule $schedule
- * @return void
- */
- protected function schedule (Schedule $schedule) : void {
- $schedule->command('inspire')
- ->hourly();
- }
+ /**
+ * Define the application's command schedule.
+ *
+ * @param \Illuminate\Console\Scheduling\Schedule $schedule
+ * @return void
+ */
+ protected function schedule( Schedule $schedule ): void {
+ $schedule->command( 'inspire' )
+ ->hourly();
+ }
- /**
- * Gets a command by name
- *
- * @throws \RuntimeException when command doesn't exit
- */
- public function get (string $name) : Command {
- $commands = $this->all();
+ /**
+ * Gets a command by name
+ *
+ * @throws \RuntimeException when command doesn't exit
+ */
+ public function get( string $name ): Command {
+ $commands = $this->all();
- if (array_key_exists($name, $commands)) {
- return $commands[$name];
- }
+ if ( array_key_exists( $name, $commands ) ) {
+ return $commands[$name];
+ }
- throw new \RuntimeException("Command $name doesn't exist.");
- }
+ throw new \RuntimeException( "Command $name doesn't exist." );
+ }
- /**
- * Gets a command by class
- *
- * @param string $class The command class
- * @return \Illuminate\Console\Command
- * @throws \RuntimeException when command doesn't exit
- */
- public function getByClass (string $class) : Command {
- $commands = $this->all();
+ /**
+ * Gets a command by class
+ *
+ * @param string $class The command class
+ * @return \Illuminate\Console\Command
+ * @throws \RuntimeException when command doesn't exit
+ */
+ public function getByClass( string $class ): Command {
+ $commands = $this->all();
- foreach ($commands as $command) {
- if ($command instanceof $class) {
- return $command;
- }
- }
+ foreach ( $commands as $command ) {
+ if ( $command instanceof $class ) {
+ return $command;
+ }
+ }
- throw new \RuntimeException("Command $class doesn't exist.");
- }
+ throw new \RuntimeException( "Command $class doesn't exist." );
+ }
}
diff --git a/app/Contracts/APIClient.php b/app/Contracts/APIClient.php
--- a/app/Contracts/APIClient.php
+++ b/app/Contracts/APIClient.php
@@ -4,21 +4,21 @@
interface APIClient {
- /**
- * Sets API end point
- *
- * @param string $url The API end point URL
- * @return void
- */
- public function setEndPoint ($url);
+ /**
+ * Sets API end point
+ *
+ * @param string $url The API end point URL
+ * @return void
+ */
+ public function setEndPoint( string $url );
- /**
- * Calls an API method
- *
- * @param string $method The method to call
- * @param array $arguments The arguments to use
- * @return mixed The API result
- */
- public function call ($method, $arguments = []);
+ /**
+ * Calls an API method
+ *
+ * @param string $method The method to call
+ * @param array $arguments The arguments to use
+ * @return mixed The API result
+ */
+ public function call( string $method, array $arguments = [] );
}
diff --git a/app/Contracts/APIFactory.php b/app/Contracts/APIFactory.php
--- a/app/Contracts/APIFactory.php
+++ b/app/Contracts/APIFactory.php
@@ -4,12 +4,12 @@
interface APIFactory {
- /**
- * Gets an instance of the API client class
- *
- * @param string $endPoint The API end point
- * @return APIClient
- */
- public function get ($endPoint);
+ /**
+ * Gets an instance of the API client class
+ *
+ * @param string $endPoint The API end point
+ * @return APIClient
+ */
+ public function get( string $endPoint );
}
diff --git a/app/Events/DockerHubPayloadEvent.php b/app/Events/DockerHubPayloadEvent.php
--- a/app/Events/DockerHubPayloadEvent.php
+++ b/app/Events/DockerHubPayloadEvent.php
@@ -2,52 +2,51 @@
namespace Nasqueron\Notifications\Events;
-use Nasqueron\Notifications\Events\Event;
use Illuminate\Queue\SerializesModels;
class DockerHubPayloadEvent extends Event {
- use SerializesModels;
-
- /**
- * The gate door which receives the request
- * @var string
- */
- public $door;
-
- /**
- * The event triggering this request
- * @var string
- */
- public $event;
-
- /**
- * The request content, as a structured data
- * @var \stdClass
- */
- public $payload;
-
- /**
- * Gets event according the kind of payload we receive.
- *
- * @return string
- */
- public function getEvent () : string {
- if (isset($this->payload->repository->repo_url)) {
- return "push";
- }
-
- return "buildFailure";
- }
-
- /**
- * Creates a new event instance.
- *
- * @param string $door
- * @param \stdClass $payload
- */
- public function __construct($door, $payload) {
- $this->door = $door;
- $this->payload = $payload;
- $this->event = $this->getEvent();
- }
+ use SerializesModels;
+
+ /**
+ * The gate door which receives the request
+ * @var string
+ */
+ public $door;
+
+ /**
+ * The event triggering this request
+ * @var string
+ */
+ public $event;
+
+ /**
+ * The request content, as a structured data
+ * @var \stdClass
+ */
+ public $payload;
+
+ /**
+ * Gets event according the kind of payload we receive.
+ *
+ * @return string
+ */
+ public function getEvent(): string {
+ if ( isset( $this->payload->repository->repo_url ) ) {
+ return "push";
+ }
+
+ return "buildFailure";
+ }
+
+ /**
+ * Creates a new event instance.
+ *
+ * @param string $door
+ * @param \stdClass $payload
+ */
+ public function __construct( $door, $payload ) {
+ $this->door = $door;
+ $this->payload = $payload;
+ $this->event = $this->getEvent();
+ }
}
diff --git a/app/Events/Event.php b/app/Events/Event.php
--- a/app/Events/Event.php
+++ b/app/Events/Event.php
@@ -4,10 +4,10 @@
abstract class Event {
- /**
- * The request content, as a structured data
- * @var mixed
- */
- public $payload;
+ /**
+ * The request content, as a structured data
+ * @var mixed
+ */
+ public $payload;
}
diff --git a/app/Events/GitHubPayloadEvent.php b/app/Events/GitHubPayloadEvent.php
--- a/app/Events/GitHubPayloadEvent.php
+++ b/app/Events/GitHubPayloadEvent.php
@@ -2,40 +2,39 @@
namespace Nasqueron\Notifications\Events;
-use Nasqueron\Notifications\Events\Event;
use Illuminate\Queue\SerializesModels;
class GitHubPayloadEvent extends Event {
- use SerializesModels;
+ use SerializesModels;
- /**
- * The gate door which receives the request
- * @var string
- */
- public $door;
+ /**
+ * The gate door which receives the request
+ * @var string
+ */
+ public $door;
- /**
- * The GitHub event triggering this request
- * @var string
- */
- public $event;
+ /**
+ * The GitHub event triggering this request
+ * @var string
+ */
+ public $event;
- /**
- * The request content, as a structured data
- * @var \stdClass
- */
- public $payload;
+ /**
+ * The request content, as a structured data
+ * @var \stdClass
+ */
+ public $payload;
- /**
- * Creates a new event instance.
- *
- * @param string $door
- * @param string $event
- * @param \stdClass $payload
- */
- public function __construct($door, $event, $payload) {
- $this->door = $door;
- $this->event = $event;
- $this->payload = $payload;
- }
+ /**
+ * Creates a new event instance.
+ *
+ * @param string $door
+ * @param string $event
+ * @param \stdClass $payload
+ */
+ public function __construct( $door, $event, $payload ) {
+ $this->door = $door;
+ $this->event = $event;
+ $this->payload = $payload;
+ }
}
diff --git a/app/Events/JenkinsPayloadEvent.php b/app/Events/JenkinsPayloadEvent.php
--- a/app/Events/JenkinsPayloadEvent.php
+++ b/app/Events/JenkinsPayloadEvent.php
@@ -2,32 +2,31 @@
namespace Nasqueron\Notifications\Events;
-use Nasqueron\Notifications\Events\Event;
use Illuminate\Queue\SerializesModels;
class JenkinsPayloadEvent extends Event {
- use SerializesModels;
+ use SerializesModels;
- /**
- * The gate door which receives the request
- * @var string
- */
- public $door;
+ /**
+ * The gate door which receives the request
+ * @var string
+ */
+ public $door;
- /**
- * The request content, as a structured data
- * @var \stdClass
- */
- public $payload;
+ /**
+ * The request content, as a structured data
+ * @var \stdClass
+ */
+ public $payload;
- /**
- * Creates a new event instance.
- *
- * @param string $door
- * @param \stdClass $payload
- */
- public function __construct($door, $payload) {
- $this->door = $door;
- $this->payload = $payload;
- }
+ /**
+ * Creates a new event instance.
+ *
+ * @param string $door
+ * @param \stdClass $payload
+ */
+ public function __construct( $door, $payload ) {
+ $this->door = $door;
+ $this->payload = $payload;
+ }
}
diff --git a/app/Events/NotificationEvent.php b/app/Events/NotificationEvent.php
--- a/app/Events/NotificationEvent.php
+++ b/app/Events/NotificationEvent.php
@@ -2,25 +2,23 @@
namespace Nasqueron\Notifications\Events;
-use Nasqueron\Notifications\Events\Event;
-use Nasqueron\Notifications\Notifications\Notification;
-
use Illuminate\Queue\SerializesModels;
+use Nasqueron\Notifications\Notifications\Notification;
class NotificationEvent extends Event {
- use SerializesModels;
+ use SerializesModels;
- /**
- * @var Notification
- */
- public $notification;
+ /**
+ * @var Notification
+ */
+ public $notification;
- /**
- * Creates a new event instance.
- *
- * @param Notification $notification the notification
- */
- public function __construct(Notification $notification) {
- $this->notification = $notification;
- }
+ /**
+ * Creates a new event instance.
+ *
+ * @param Notification $notification the notification
+ */
+ public function __construct( Notification $notification ) {
+ $this->notification = $notification;
+ }
}
diff --git a/app/Events/PhabricatorPayloadEvent.php b/app/Events/PhabricatorPayloadEvent.php
--- a/app/Events/PhabricatorPayloadEvent.php
+++ b/app/Events/PhabricatorPayloadEvent.php
@@ -2,53 +2,52 @@
namespace Nasqueron\Notifications\Events;
-use Nasqueron\Notifications\Events\Event;
-use Nasqueron\Notifications\Phabricator\PhabricatorStory;
use Illuminate\Queue\SerializesModels;
+use Nasqueron\Notifications\Phabricator\PhabricatorStory;
class PhabricatorPayloadEvent extends Event {
- use SerializesModels;
-
- /**
- * The gate door which receives the request
- * @var string
- */
- public $door;
-
- /**
- * The raw payload
- * @var iterable
- */
- public $payload;
-
- /**
- * The story sent by the request
- * @var PhabricatorStory
- */
- public $story;
-
- /**
- * Gets story from the request
- *
- * @return PhabricatorStory
- */
- protected function getStory () {
- return PhabricatorStory::loadFromIterable(
- $this->door,
- $this->payload
- );
- }
-
- /**
- * Creates a new event instance.
- *
- * @param string $door
- * @param iterable $payload
- */
- public function __construct(string $door, iterable $payload) {
- $this->door = $door;
- $this->payload = $payload;
-
- $this->story = $this->getStory();
- }
+ use SerializesModels;
+
+ /**
+ * The gate door which receives the request
+ * @var string
+ */
+ public $door;
+
+ /**
+ * The raw payload
+ * @var iterable
+ */
+ public $payload;
+
+ /**
+ * The story sent by the request
+ * @var PhabricatorStory
+ */
+ public $story;
+
+ /**
+ * Gets story from the request
+ *
+ * @return PhabricatorStory
+ */
+ protected function getStory() {
+ return PhabricatorStory::loadFromIterable(
+ $this->door,
+ $this->payload
+ );
+ }
+
+ /**
+ * Creates a new event instance.
+ *
+ * @param string $door
+ * @param iterable $payload
+ */
+ public function __construct( string $door, iterable $payload ) {
+ $this->door = $door;
+ $this->payload = $payload;
+
+ $this->story = $this->getStory();
+ }
}
diff --git a/app/Events/ReportEvent.php b/app/Events/ReportEvent.php
--- a/app/Events/ReportEvent.php
+++ b/app/Events/ReportEvent.php
@@ -2,24 +2,23 @@
namespace Nasqueron\Notifications\Events;
-use Nasqueron\Notifications\Actions\Action;
-use Nasqueron\Notifications\Events\Event;
use Illuminate\Queue\SerializesModels;
+use Nasqueron\Notifications\Actions\Action;
class ReportEvent extends Event {
- use SerializesModels;
+ use SerializesModels;
- /**
- * @var Action
- */
- public $action;
+ /**
+ * @var Action
+ */
+ public $action;
- /**
- * Creates a new event instance.
- *
- * @param Action $action the action to report
- */
- public function __construct(Action $action) {
- $this->action = $action;
- }
+ /**
+ * Creates a new event instance.
+ *
+ * @param Action $action the action to report
+ */
+ public function __construct( Action $action ) {
+ $this->action = $action;
+ }
}
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
--- a/app/Exceptions/Handler.php
+++ b/app/Exceptions/Handler.php
@@ -2,73 +2,70 @@
namespace Nasqueron\Notifications\Exceptions;
-use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
-
+use Config;
+use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
+use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Foundation\Validation\ValidationException;
use Illuminate\Session\TokenMismatchException;
use Psr\Log\LoggerInterface;
+use Raven;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
-use Config;
-use Raven;
-
-use Exception;
-
class Handler extends ExceptionHandler {
- /**
- * A list of the exception types that should not be reported.
- *
- * @var string[]
- */
- protected $dontReport = [
- AuthorizationException::class,
- CommandNotFoundException::class,
- HttpException::class,
- ModelNotFoundException::class,
- TokenMismatchException::class,
- ValidationException::class,
- ];
+ /**
+ * A list of the exception types that should not be reported.
+ *
+ * @var string[]
+ */
+ protected $dontReport = [
+ AuthorizationException::class,
+ CommandNotFoundException::class,
+ HttpException::class,
+ ModelNotFoundException::class,
+ TokenMismatchException::class,
+ ValidationException::class,
+ ];
- /**
- * Reports or logs an exception.
- *
- * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
- *
- * @param \Exception $e
- */
- public function report(Exception $e) : void {
- if (!$this->shouldReport($e)) {
- return;
- }
+ /**
+ * Reports or logs an exception.
+ *
+ * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
+ *
+ * @param \Exception $e
+ */
+ public function report( \Throwable $e ): void {
+ if ( !$this->shouldReport( $e ) ) {
+ return;
+ }
- if ($this->shouldReportToSentry()) {
- $this->reportToSentry($e);
- }
+ if ( $this->shouldReportToSentry() ) {
+ $this->reportToSentry( $e );
+ }
- $log = $this->container->make(LoggerInterface::class);
- $log->error((string)$e);
- }
+ $log = $this->container->make( LoggerInterface::class );
+ $log->error( (string)$e );
+ }
- /**
- * Determines if the error handler should report to Sentry
- *
- * @return bool
- */
- protected function shouldReportToSentry () : bool {
- return Raven::isConfigured() && Config::get('app.env') !== 'testing';
- }
+ /**
+ * Determines if the error handler should report to Sentry
+ *
+ * @return bool
+ */
+ protected function shouldReportToSentry(): bool {
+ return Raven::isConfigured() && Config::get( 'app.env' ) !== 'testing';
+ }
- /**
- * Reports the exception to Sentry
- *
- * @param Exception $e The exception to report
- */
- protected function reportToSentry (Exception $e) : void {
- Raven::captureException($e);
- }
+ /**
+ * Reports the exception to Sentry
+ *
+ * @param Exception $e The exception to report
+ */
+ protected function reportToSentry( Exception $e ): void {
+ Raven::captureException( $e );
+ }
}
diff --git a/app/Facades/Broker.php b/app/Facades/Broker.php
--- a/app/Facades/Broker.php
+++ b/app/Facades/Broker.php
@@ -9,13 +9,13 @@
*/
class Broker extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'broker';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'broker';
+ }
}
diff --git a/app/Facades/DockerHub.php b/app/Facades/DockerHub.php
--- a/app/Facades/DockerHub.php
+++ b/app/Facades/DockerHub.php
@@ -9,13 +9,13 @@
*/
class DockerHub extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'dockerhub';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'dockerhub';
+ }
}
diff --git a/app/Facades/Mailgun.php b/app/Facades/Mailgun.php
--- a/app/Facades/Mailgun.php
+++ b/app/Facades/Mailgun.php
@@ -9,13 +9,13 @@
*/
class Mailgun extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'mailgun';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'mailgun';
+ }
}
diff --git a/app/Facades/PhabricatorAPI.php b/app/Facades/PhabricatorAPI.php
--- a/app/Facades/PhabricatorAPI.php
+++ b/app/Facades/PhabricatorAPI.php
@@ -9,13 +9,13 @@
*/
class PhabricatorAPI extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'phabricator-api';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'phabricator-api';
+ }
}
diff --git a/app/Facades/ProjectsMap.php b/app/Facades/ProjectsMap.php
--- a/app/Facades/ProjectsMap.php
+++ b/app/Facades/ProjectsMap.php
@@ -9,13 +9,13 @@
*/
class ProjectsMap extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'phabricator-projectsmap';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'phabricator-projectsmap';
+ }
}
diff --git a/app/Facades/Raven.php b/app/Facades/Raven.php
--- a/app/Facades/Raven.php
+++ b/app/Facades/Raven.php
@@ -2,28 +2,27 @@
namespace Nasqueron\Notifications\Facades;
-use Illuminate\Support\Facades\Facade;
-
use Config;
+use Illuminate\Support\Facades\Facade;
/**
* @see \Raven_Client
*/
class Raven extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'raven';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'raven';
+ }
- /**
- * Determines if a Sentry DSN is provided in the configuration
- */
- public static function isConfigured () : bool {
- return Config::get('services.sentry.dsn') !== null;
- }
+ /**
+ * Determines if a Sentry DSN is provided in the configuration
+ */
+ public static function isConfigured(): bool {
+ return Config::get( 'services.sentry.dsn' ) !== null;
+ }
}
diff --git a/app/Facades/Report.php b/app/Facades/Report.php
--- a/app/Facades/Report.php
+++ b/app/Facades/Report.php
@@ -9,13 +9,13 @@
*/
class Report extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'report';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'report';
+ }
}
diff --git a/app/Facades/Services.php b/app/Facades/Services.php
--- a/app/Facades/Services.php
+++ b/app/Facades/Services.php
@@ -9,13 +9,13 @@
*/
class Services extends Facade {
- /**
- * Gets the registered name of the component.
- *
- * @return string
- */
- protected static function getFacadeAccessor() : string {
- return 'services';
- }
+ /**
+ * Gets the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string {
+ return 'services';
+ }
}
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -2,12 +2,14 @@
namespace Nasqueron\Notifications\Http\Controllers;
+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
-use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
-use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Routing\Controller as BaseController;
abstract class Controller extends BaseController {
- use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+ use AuthorizesRequests;
+ use DispatchesJobs;
+ use ValidatesRequests;
}
diff --git a/app/Http/Controllers/Gate/DockerHubGateController.php b/app/Http/Controllers/Gate/DockerHubGateController.php
--- a/app/Http/Controllers/Gate/DockerHubGateController.php
+++ b/app/Http/Controllers/Gate/DockerHubGateController.php
@@ -2,82 +2,80 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
-use Nasqueron\Notifications\Events\DockerHubPayloadEvent;
-
-use Symfony\Component\HttpFoundation\Response;
-
use Event;
+use Nasqueron\Notifications\Events\DockerHubPayloadEvent;
use Request;
+use Symfony\Component\HttpFoundation\Response;
class DockerHubGateController extends GateController {
- ///
- /// Private members
- ///
-
- /**
- * The request content, as a structured data
- *
- * @var \stdClass
- */
- private $payload;
-
- /**
- * The request content
- *
- * @var string
- */
- private $rawRequestContent;
-
- ///
- /// Request processing
- ///
-
- /**
- * Handles POST requests
- *
- * @param string $door The door, matching the project for this payload
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function onPost (string $door) : Response {
- // Parses the request and check if it's legit
-
- $this->door = $door;
- $this->extractPayload();
-
- // Process the request
-
- $this->logRequest();
- $this->onPayload();
-
- // Output
-
- return parent::renderReport();
- }
-
- /**
- * Extracts payload from the request
- */
- protected function extractPayload () : void {
- $request = Request::instance();
- $this->rawRequestContent = $request->getContent();
- $this->payload = json_decode($this->rawRequestContent);
- }
-
- public function getServiceName () : string {
- return "DockerHub";
- }
-
- ///
- /// Payload processing
- ///
-
- protected function onPayload () : void {
- $this->initializeReport();
-
- Event::fire(new DockerHubPayloadEvent(
- $this->door,
- $this->payload
- ));
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The request content, as a structured data
+ *
+ * @var \stdClass
+ */
+ private $payload;
+
+ /**
+ * The request content
+ *
+ * @var string
+ */
+ private $rawRequestContent;
+
+ ///
+ /// Request processing
+ ///
+
+ /**
+ * Handles POST requests
+ *
+ * @param string $door The door, matching the project for this payload
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function onPost( string $door ): Response {
+ // Parses the request and check if it's legit
+
+ $this->door = $door;
+ $this->extractPayload();
+
+ // Process the request
+
+ $this->logRequest();
+ $this->onPayload();
+
+ // Output
+
+ return parent::renderReport();
+ }
+
+ /**
+ * Extracts payload from the request
+ */
+ protected function extractPayload(): void {
+ $request = Request::instance();
+ $this->rawRequestContent = $request->getContent();
+ $this->payload = json_decode( $this->rawRequestContent );
+ }
+
+ public function getServiceName(): string {
+ return "DockerHub";
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload(): void {
+ $this->initializeReport();
+
+ Event::fire( new DockerHubPayloadEvent(
+ $this->door,
+ $this->payload
+ ) );
+ }
}
diff --git a/app/Http/Controllers/Gate/GateController.php b/app/Http/Controllers/Gate/GateController.php
--- a/app/Http/Controllers/Gate/GateController.php
+++ b/app/Http/Controllers/Gate/GateController.php
@@ -2,120 +2,118 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
+use App;
+use Illuminate\View\View;
+use Log;
use Nasqueron\Notifications\Config\Features;
use Nasqueron\Notifications\Config\Services\Service;
use Nasqueron\Notifications\Http\Controllers\Controller;
-
-use Symfony\Component\HttpFoundation\Response as BaseResponse;
-use Illuminate\View\View;
-
-use App;
-use Log;
use Report;
use Response;
use Services;
+use Symfony\Component\HttpFoundation\Response as BaseResponse;
/**
* Represents a controller handling an entry-point for API payloads
*/
class GateController extends Controller {
- ///
- /// Private members
- ///
-
- /**
- * @var string
- */
- protected $door;
-
- ///
- /// Requests
- ///
-
- /**
- * Handles GET requests
- */
- public function onGet () : View {
- // Virtually all the push APIs will send they payloads
- // using a POST request, so we can provide a sensible
- // default GET error message.
- return view('gate/ispostonly');
- }
-
- /**
- * Logs the request
- */
- protected function logRequest (array $extraContextualData = []) : void {
- Log::info('[Gate] New payload.', [
- 'service' => $this->getServiceName(),
- 'door' => $this->door,
- ] + $extraContextualData);
- }
-
- ///
- /// Reports
- ///
-
- /**
- * Initializes the report and registers it
- */
- protected function initializeReport () : void {
- if (Features::isEnabled('ActionsReport')) {
- Report::attachToGate($this->getServiceName(), $this->door);
- }
- }
-
- /**
- * Renders the report
- *
- * @return \Symfony\Component\HttpFoundation\Response
- */
- protected function renderReport () : BaseResponse {
- if (!Features::isEnabled('ActionsReport')) {
- return response("");
- }
-
- $report = App::make('report');
- $statusCode = $report->containsError() ? 503 : 200;
- return Response::json($report)
- ->setStatusCode($statusCode);
- }
-
- ///
- /// Credentials
- ///
-
- /**
- * Gets service credentials for this gate and door
- */
- public function getService () : ?Service {
- return Services::findServiceByDoor(
- $this->getServiceName(),
- $this->door
- );
- }
-
- /**
- * Checks if a registered service exists for this service and door.
- */
- protected function doesServiceExist () : bool {
- return $this->getService() !== null;
- }
-
- /**
- * Gets secret for this service and door.
- *
- * @return string the secret, or if unknown, an empty string
- */
- protected function getSecret () : string {
- $service= $this->getService();
-
- if ($service !== null) {
- return $service->secret;
- }
-
- return "";
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * @var string
+ */
+ protected $door;
+
+ ///
+ /// Requests
+ ///
+
+ /**
+ * Handles GET requests
+ */
+ public function onGet(): View {
+ // Virtually all the push APIs will send they payloads
+ // using a POST request, so we can provide a sensible
+ // default GET error message.
+ return view( 'gate/ispostonly' );
+ }
+
+ /**
+ * Logs the request
+ */
+ protected function logRequest( array $extraContextualData = [] ): void {
+ Log::info( '[Gate] New payload.', [
+ 'service' => $this->getServiceName(),
+ 'door' => $this->door,
+ ] + $extraContextualData );
+ }
+
+ ///
+ /// Reports
+ ///
+
+ /**
+ * Initializes the report and registers it
+ */
+ protected function initializeReport(): void {
+ if ( Features::isEnabled( 'ActionsReport' ) ) {
+ Report::attachToGate( $this->getServiceName(), $this->door );
+ }
+ }
+
+ /**
+ * Renders the report
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ protected function renderReport(): BaseResponse {
+ if ( !Features::isEnabled( 'ActionsReport' ) ) {
+ return response( "" );
+ }
+
+ $report = App::make( 'report' );
+ $statusCode = $report->containsError() ? 503 : 200;
+ return Response::json( $report )
+ ->setStatusCode( $statusCode );
+ }
+
+ ///
+ /// Credentials
+ ///
+
+ /**
+ * Gets service credentials for this gate and door
+ */
+ public function getService(): ?Service {
+ return Services::findServiceByDoor(
+ $this->getServiceName(),
+ $this->door
+ );
+ }
+
+ /**
+ * Checks if a registered service exists for this service and door.
+ */
+ protected function doesServiceExist(): bool {
+ return $this->getService() !== null;
+ }
+
+ /**
+ * Gets secret for this service and door.
+ *
+ * @return string the secret, or if unknown, an empty string
+ */
+ protected function getSecret(): string {
+ $service = $this->getService();
+
+ if ( $service !== null ) {
+ return $service->secret;
+ }
+
+ return "";
+ }
}
diff --git a/app/Http/Controllers/Gate/GitHubGateController.php b/app/Http/Controllers/Gate/GitHubGateController.php
--- a/app/Http/Controllers/Gate/GitHubGateController.php
+++ b/app/Http/Controllers/Gate/GitHubGateController.php
@@ -2,188 +2,186 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
-use Nasqueron\Notifications\Events\GitHubPayloadEvent;
-
-use Keruald\GitHub\XHubSignature;
-use Symfony\Component\HttpFoundation\Response;
-
use Event;
+use Keruald\GitHub\XHubSignature;
+use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Request;
+use Symfony\Component\HttpFoundation\Response;
class GitHubGateController extends GateController {
- ///
- /// Private members
- ///
-
- /**
- * The request signature, allowing to determine if the payload is legit
- *
- * @var string
- */
- private $signature;
-
- /**
- * The GitHub event triggering this request
- *
- * @var string
- */
- private $event;
-
- /**
- * The request delivery GUID
- *
- * @var string
- */
- private $delivery;
-
- /**
- * The request content, as a structured data
- *
- * @var \stdClass
- */
- private $payload;
-
- /**
- * The request content
- *
- * @var string
- */
- private $rawRequestContent;
-
- ///
- /// Request processing
- ///
-
- /**
- * Handles POST requests
- *
- * @param string $door The door, matching the project for this payload
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function onPost (string $door) : Response {
- // Parses the request and check if it's legit
-
- $this->door = $door;
- $this->extractHeaders();
- $this->extractPayload();
-
- if (!$this->isLegitRequest()) {
- abort(403, 'Unauthorized action.');
- }
-
- if (!$this->isValidRequest()) {
- abort(400, 'Bad request.');
- }
-
- // Process the request
-
- $this->logGateRequest();
- $this->onPayload();
-
- // Output
-
- return parent::renderReport();
- }
-
- /**
- * Extracts headers from the request
- */
- protected function extractHeaders () : void {
- $this->signature = $this->getSignature();
- $this->event = Request::header('X-Github-Event');
- $this->delivery = Request::header('X-Github-Delivery');
- }
-
- /**
- * Gets the signature from an X-Hub-Signature header
- *
- * @return string The signature part of the header
- */
- private function getSignature () : string {
- $headerSignature = Request::header('X-Hub-Signature');
- return XHubSignature::parseSignature($headerSignature);
- }
-
- /**
- * Extracts payload from the request
- */
- protected function extractPayload () : void {
- $request = Request::instance();
- $this->rawRequestContent = $request->getContent();
- $this->payload = json_decode($this->rawRequestContent);
- }
-
- /**
- * Determines if the request is valid, ie contains the mandatory headers
- * and a payload.
- *
- * @return bool true if the request looks valid; otherwise, false.
- */
- protected function isValidRequest () : bool {
- if (empty($this->event)) {
- return false;
- }
- if (empty($this->delivery)) {
- return false;
- }
- if (empty($this->payload) || !is_object($this->payload)) {
- return false;
- }
- return true;
- }
-
- /**
- * Determines if the request is legit.
- *
- * @return bool true if the request looks legit; otherwise, false.
- */
- protected function isLegitRequest () : bool {
- $secret = $this->getSecret();
-
- // If the secret is not defined, request legitimation is bypassed
- if (empty($secret)) {
- return true;
- }
-
- // If the secret is defined, but signature is missing from the
- // request, we don't need to perform any other validation.
- if (empty($this->signature)) {
- return false;
- }
-
- return XHubSignature::validatePayload(
- $secret,
- $this->rawRequestContent,
- $this->signature
- );
- }
-
- /**
- * Logs the request
- */
- protected function logGateRequest () {
- $this->logRequest([
- 'delivery' => $this->delivery,
- 'event' => $this->event,
- ]);
- }
-
- public function getServiceName () : string {
- return "GitHub";
- }
-
- ///
- /// Payload processing
- ///
-
- protected function onPayload () {
- $this->initializeReport();
-
- Event::fire(new GitHubPayloadEvent(
- $this->door,
- $this->event,
- $this->payload
- ));
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The request signature, allowing to determine if the payload is legit
+ *
+ * @var string
+ */
+ private $signature;
+
+ /**
+ * The GitHub event triggering this request
+ *
+ * @var string
+ */
+ private $event;
+
+ /**
+ * The request delivery GUID
+ *
+ * @var string
+ */
+ private $delivery;
+
+ /**
+ * The request content, as a structured data
+ *
+ * @var \stdClass
+ */
+ private $payload;
+
+ /**
+ * The request content
+ *
+ * @var string
+ */
+ private $rawRequestContent;
+
+ ///
+ /// Request processing
+ ///
+
+ /**
+ * Handles POST requests
+ *
+ * @param string $door The door, matching the project for this payload
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function onPost( string $door ): Response {
+ // Parses the request and check if it's legit
+
+ $this->door = $door;
+ $this->extractHeaders();
+ $this->extractPayload();
+
+ if ( !$this->isLegitRequest() ) {
+ abort( 403, 'Unauthorized action.' );
+ }
+
+ if ( !$this->isValidRequest() ) {
+ abort( 400, 'Bad request.' );
+ }
+
+ // Process the request
+
+ $this->logGateRequest();
+ $this->onPayload();
+
+ // Output
+
+ return parent::renderReport();
+ }
+
+ /**
+ * Extracts headers from the request
+ */
+ protected function extractHeaders(): void {
+ $this->signature = $this->getSignature();
+ $this->event = Request::header( 'X-Github-Event' );
+ $this->delivery = Request::header( 'X-Github-Delivery' );
+ }
+
+ /**
+ * Gets the signature from an X-Hub-Signature header
+ *
+ * @return string The signature part of the header
+ */
+ private function getSignature(): string {
+ $headerSignature = Request::header( 'X-Hub-Signature' );
+ return XHubSignature::parseSignature( $headerSignature );
+ }
+
+ /**
+ * Extracts payload from the request
+ */
+ protected function extractPayload(): void {
+ $request = Request::instance();
+ $this->rawRequestContent = $request->getContent();
+ $this->payload = json_decode( $this->rawRequestContent );
+ }
+
+ /**
+ * Determines if the request is valid, ie contains the mandatory headers
+ * and a payload.
+ *
+ * @return bool true if the request looks valid; otherwise, false.
+ */
+ protected function isValidRequest(): bool {
+ if ( empty( $this->event ) ) {
+ return false;
+ }
+ if ( empty( $this->delivery ) ) {
+ return false;
+ }
+ if ( empty( $this->payload ) || !is_object( $this->payload ) ) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Determines if the request is legit.
+ *
+ * @return bool true if the request looks legit; otherwise, false.
+ */
+ protected function isLegitRequest(): bool {
+ $secret = $this->getSecret();
+
+ // If the secret is not defined, request legitimation is bypassed
+ if ( empty( $secret ) ) {
+ return true;
+ }
+
+ // If the secret is defined, but signature is missing from the
+ // request, we don't need to perform any other validation.
+ if ( empty( $this->signature ) ) {
+ return false;
+ }
+
+ return XHubSignature::validatePayload(
+ $secret,
+ $this->rawRequestContent,
+ $this->signature
+ );
+ }
+
+ /**
+ * Logs the request
+ */
+ protected function logGateRequest() {
+ $this->logRequest( [
+ 'delivery' => $this->delivery,
+ 'event' => $this->event,
+ ] );
+ }
+
+ public function getServiceName(): string {
+ return "GitHub";
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload() {
+ $this->initializeReport();
+
+ Event::fire( new GitHubPayloadEvent(
+ $this->door,
+ $this->event,
+ $this->payload
+ ) );
+ }
}
diff --git a/app/Http/Controllers/Gate/JenkinsGateController.php b/app/Http/Controllers/Gate/JenkinsGateController.php
--- a/app/Http/Controllers/Gate/JenkinsGateController.php
+++ b/app/Http/Controllers/Gate/JenkinsGateController.php
@@ -2,82 +2,80 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
-use Nasqueron\Notifications\Events\JenkinsPayloadEvent;
-
-use Symfony\Component\HttpFoundation\Response;
-
use Event;
+use Nasqueron\Notifications\Events\JenkinsPayloadEvent;
use Request;
+use Symfony\Component\HttpFoundation\Response;
class JenkinsGateController extends GateController {
- ///
- /// Private members
- ///
-
- /**
- * The request content, as a structured data
- *
- * @var \stdClass
- */
- private $payload;
-
- /**
- * The request content
- *
- * @var string
- */
- private $rawRequestContent;
-
- ///
- /// Request processing
- ///
-
- /**
- * Handles POST requests
- *
- * @param string $door The door, matching the project for this payload
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function onPost (string $door) : Response {
- // Parses the request and check if it's legit
-
- $this->door = $door;
- $this->extractPayload();
-
- // Process the request
-
- $this->logRequest();
- $this->onPayload();
-
- // Output
-
- return parent::renderReport();
- }
-
- /**
- * Extracts payload from the request
- */
- protected function extractPayload () {
- $request = Request::instance();
- $this->rawRequestContent = $request->getContent();
- $this->payload = json_decode($this->rawRequestContent);
- }
-
- public function getServiceName () : string {
- return "Jenkins";
- }
-
- ///
- /// Payload processing
- ///
-
- protected function onPayload () {
- $this->initializeReport();
-
- Event::fire(new JenkinsPayloadEvent(
- $this->door,
- $this->payload
- ));
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The request content, as a structured data
+ *
+ * @var \stdClass
+ */
+ private $payload;
+
+ /**
+ * The request content
+ *
+ * @var string
+ */
+ private $rawRequestContent;
+
+ ///
+ /// Request processing
+ ///
+
+ /**
+ * Handles POST requests
+ *
+ * @param string $door The door, matching the project for this payload
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function onPost( string $door ): Response {
+ // Parses the request and check if it's legit
+
+ $this->door = $door;
+ $this->extractPayload();
+
+ // Process the request
+
+ $this->logRequest();
+ $this->onPayload();
+
+ // Output
+
+ return parent::renderReport();
+ }
+
+ /**
+ * Extracts payload from the request
+ */
+ protected function extractPayload() {
+ $request = Request::instance();
+ $this->rawRequestContent = $request->getContent();
+ $this->payload = json_decode( $this->rawRequestContent );
+ }
+
+ public function getServiceName(): string {
+ return "Jenkins";
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload() {
+ $this->initializeReport();
+
+ Event::fire( new JenkinsPayloadEvent(
+ $this->door,
+ $this->payload
+ ) );
+ }
}
diff --git a/app/Http/Controllers/Gate/NotificationGateController.php b/app/Http/Controllers/Gate/NotificationGateController.php
--- a/app/Http/Controllers/Gate/NotificationGateController.php
+++ b/app/Http/Controllers/Gate/NotificationGateController.php
@@ -2,138 +2,135 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
+use Event;
+use InvalidArgumentException;
use Nasqueron\Notifications\Events\NotificationEvent;
use Nasqueron\Notifications\Notifications\Notification;
-
-use Symfony\Component\HttpFoundation\Response;
-
-use Event;
use Request;
-
-use InvalidArgumentException;
+use Symfony\Component\HttpFoundation\Response;
class NotificationGateController extends GateController {
- ///
- /// Private members
- ///
-
- /**
- * The request content, as a structured data
- *
- * @var \Nasqueron\Notifications\Notifications\Notification
- */
- private $payload;
-
- /**
- * The request content
- *
- * @var string
- */
- private $rawRequestContent;
-
- ///
- /// Request processing
- ///
-
- /**
- * Handles POST requests
- *
- * @param string $door The door, matching the project for this payload
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function onPost (string $door) : Response {
- // Parses the request and check if it's legit
-
- $this->door = $door;
-
- try {
- $this->extractPayload();
- $this->normalizePayload();
- } catch (InvalidArgumentException $ex) {
- abort(400, 'Bad request.');
- }
-
- // Process the request
-
- $this->logRequest();
- $this->onPayload();
-
- // Output
-
- return parent::renderReport();
- }
-
- /**
- * Extracts payload from the request
- */
- protected function extractPayload () {
- $request = Request::instance();
- $this->rawRequestContent = $request->getContent();
- $this->payload = $this->getNotification();
- }
-
- protected function getServiceName () : string {
- return (string)$this->payload->service;
- }
-
- ///
- /// Helper methods to get notification
- ///
-
- private function getNotification () : Notification {
- $payload = json_decode($this->rawRequestContent);
- if ($payload === null) {
- throw new InvalidArgumentException("Invalid JSON");
- }
-
- $mapper = new \JsonMapper();
- return (Notification)($mapper->map(
- $payload,
- new Notification
- ));
- }
-
- private function normalizePayload () : void {
- $this->normalizeProject();
- $this->ensureRequiredPayloadFieldsArePresent();
- }
-
- private function normalizeProject () : void {
- if (!$this->isPayloadFieldPresent('project')) {
- $this->payload->project = $this->door;
- }
- }
-
- private function ensureRequiredPayloadFieldsArePresent () : void {
- foreach ($this->getMandatoryPayloadFields() as $field) {
- if (!$this->isPayloadFieldPresent($field)) {
- throw new InvalidArgumentException("Field $field is missing.");
- }
- }
- }
-
- private function getMandatoryPayloadFields () : array {
- return [
- 'service',
- 'project',
- 'group',
- 'type',
- ];
- }
-
- private function isPayloadFieldPresent (string $field) : bool {
- return (string)$this->payload->$field !== "";
- }
-
- ///
- /// Payload processing
- ///
-
- protected function onPayload () {
- $this->initializeReport();
-
- Event::fire(new NotificationEvent($this->payload));
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The request content, as a structured data
+ *
+ * @var \Nasqueron\Notifications\Notifications\Notification
+ */
+ private $payload;
+
+ /**
+ * The request content
+ *
+ * @var string
+ */
+ private $rawRequestContent;
+
+ ///
+ /// Request processing
+ ///
+
+ /**
+ * Handles POST requests
+ *
+ * @param string $door The door, matching the project for this payload
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function onPost( string $door ): Response {
+ // Parses the request and check if it's legit
+
+ $this->door = $door;
+
+ try {
+ $this->extractPayload();
+ $this->normalizePayload();
+ } catch ( InvalidArgumentException $ex ) {
+ abort( 400, 'Bad request.' );
+ }
+
+ // Process the request
+
+ $this->logRequest();
+ $this->onPayload();
+
+ // Output
+
+ return parent::renderReport();
+ }
+
+ /**
+ * Extracts payload from the request
+ */
+ protected function extractPayload() {
+ $request = Request::instance();
+ $this->rawRequestContent = $request->getContent();
+ $this->payload = $this->getNotification();
+ }
+
+ protected function getServiceName(): string {
+ return (string)$this->payload->service;
+ }
+
+ ///
+ /// Helper methods to get notification
+ ///
+
+ private function getNotification(): Notification {
+ $payload = json_decode( $this->rawRequestContent );
+ if ( $payload === null ) {
+ throw new InvalidArgumentException( "Invalid JSON" );
+ }
+
+ $mapper = new \JsonMapper();
+ return ( Notification )( $mapper->map(
+ $payload,
+ new Notification
+ ) );
+ }
+
+ private function normalizePayload(): void {
+ $this->normalizeProject();
+ $this->ensureRequiredPayloadFieldsArePresent();
+ }
+
+ private function normalizeProject(): void {
+ if ( !$this->isPayloadFieldPresent( 'project' ) ) {
+ $this->payload->project = $this->door;
+ }
+ }
+
+ private function ensureRequiredPayloadFieldsArePresent(): void {
+ foreach ( $this->getMandatoryPayloadFields() as $field ) {
+ if ( !$this->isPayloadFieldPresent( $field ) ) {
+ throw new InvalidArgumentException( "Field $field is missing." );
+ }
+ }
+ }
+
+ private function getMandatoryPayloadFields(): array {
+ return [
+ 'service',
+ 'project',
+ 'group',
+ 'type',
+ ];
+ }
+
+ private function isPayloadFieldPresent( string $field ): bool {
+ return (string)$this->payload->$field !== "";
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload() {
+ $this->initializeReport();
+
+ Event::fire( new NotificationEvent( $this->payload ) );
+ }
}
diff --git a/app/Http/Controllers/Gate/PhabricatorGateController.php b/app/Http/Controllers/Gate/PhabricatorGateController.php
--- a/app/Http/Controllers/Gate/PhabricatorGateController.php
+++ b/app/Http/Controllers/Gate/PhabricatorGateController.php
@@ -2,72 +2,70 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
-use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
-
-use Symfony\Component\HttpFoundation\Response;
-
use Event;
+use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
use Request;
+use Symfony\Component\HttpFoundation\Response;
class PhabricatorGateController extends GateController {
- ///
- /// Private members
- ///
-
- /**
- * The request content, as a structured data
- *
- * @var array
- */
- private $payload;
-
- ///
- /// Requests processing
- ///
-
- /**
- * Handles POST requests
- *
- * @param string $door The door, matching the project for this payload
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function onPost (string $door) : Response {
- $this->door = $door;
-
- if (!$this->doesServiceExist()) {
- abort(404, 'Unknown Phabricator instance.');
- }
-
- $this->extractPayload();
-
- $this->logRequest();
- $this->onPayload();
-
- return parent::renderReport();
- }
-
- /**
- * Extracts payload from the request
- */
- protected function extractPayload () : void {
- $this->payload = Request::all();
- }
-
- public function getServiceName () : string {
- return "Phabricator";
- }
-
- ///
- /// Payload processing
- ///
-
- protected function onPayload () : void {
- $this->initializeReport();
-
- Event::fire(new PhabricatorPayloadEvent(
- $this->door,
- $this->payload
- ));
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The request content, as a structured data
+ *
+ * @var array
+ */
+ private $payload;
+
+ ///
+ /// Requests processing
+ ///
+
+ /**
+ * Handles POST requests
+ *
+ * @param string $door The door, matching the project for this payload
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function onPost( string $door ): Response {
+ $this->door = $door;
+
+ if ( !$this->doesServiceExist() ) {
+ abort( 404, 'Unknown Phabricator instance.' );
+ }
+
+ $this->extractPayload();
+
+ $this->logRequest();
+ $this->onPayload();
+
+ return parent::renderReport();
+ }
+
+ /**
+ * Extracts payload from the request
+ */
+ protected function extractPayload(): void {
+ $this->payload = Request::all();
+ }
+
+ public function getServiceName(): string {
+ return "Phabricator";
+ }
+
+ ///
+ /// Payload processing
+ ///
+
+ protected function onPayload(): void {
+ $this->initializeReport();
+
+ Event::fire( new PhabricatorPayloadEvent(
+ $this->door,
+ $this->payload
+ ) );
+ }
}
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -6,45 +6,45 @@
class Kernel extends HttpKernel {
- /**
- * The application's global HTTP middleware stack.
- *
- * These middleware are run during every request to your application.
- *
- * @var array
- */
- protected $middleware = [
- \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
- ];
+ /**
+ * The application's global HTTP middleware stack.
+ *
+ * These middleware are run during every request to your application.
+ *
+ * @var array
+ */
+ protected $middleware = [
+ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
+ ];
- /**
- * The application's route middleware groups.
- *
- * @var array
- */
- protected $middlewareGroups = [
- 'web' => [
- \Nasqueron\Notifications\Http\Middleware\EncryptCookies::class,
- \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
- \Illuminate\Session\Middleware\StartSession::class,
- \Illuminate\View\Middleware\ShareErrorsFromSession::class,
- \Nasqueron\Notifications\Http\Middleware\VerifyCsrfToken::class,
- \Illuminate\Routing\Middleware\SubstituteBindings::class,
- ],
+ /**
+ * The application's route middleware groups.
+ *
+ * @var array
+ */
+ protected $middlewareGroups = [
+ 'web' => [
+ \Nasqueron\Notifications\Http\Middleware\EncryptCookies::class,
+ \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
+ \Illuminate\Session\Middleware\StartSession::class,
+ \Illuminate\View\Middleware\ShareErrorsFromSession::class,
+ \Nasqueron\Notifications\Http\Middleware\VerifyCsrfToken::class,
+ \Illuminate\Routing\Middleware\SubstituteBindings::class,
+ ],
- 'api' => [
- 'throttle:60,1',
- 'bindings',
- ],
- ];
+ 'api' => [
+ 'throttle:60,1',
+ 'bindings',
+ ],
+ ];
- /**
- * The application's route middleware.
- *
- * @var array
- */
- protected $routeMiddleware = [
- 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
- 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
- ];
+ /**
+ * The application's route middleware.
+ *
+ * @var array
+ */
+ protected $routeMiddleware = [
+ 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
+ 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
+ ];
}
diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php
--- a/app/Http/Middleware/EncryptCookies.php
+++ b/app/Http/Middleware/EncryptCookies.php
@@ -6,12 +6,12 @@
class EncryptCookies extends BaseEncrypter {
- /**
- * The names of the cookies that should not be encrypted.
- *
- * @var string[]
- */
- protected $except = [
- //
- ];
+ /**
+ * The names of the cookies that should not be encrypted.
+ *
+ * @var string[]
+ */
+ protected $except = [
+ //
+ ];
}
diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php
--- a/app/Http/Middleware/VerifyCsrfToken.php
+++ b/app/Http/Middleware/VerifyCsrfToken.php
@@ -6,12 +6,12 @@
class VerifyCsrfToken extends BaseVerifier {
- /**
- * The URIs that should be excluded from CSRF verification.
- *
- * @var string[]
- */
- protected $except = [
- 'gate/*',
- ];
+ /**
+ * The URIs that should be excluded from CSRF verification.
+ *
+ * @var string[]
+ */
+ protected $except = [
+ 'gate/*',
+ ];
}
diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php
--- a/app/Http/Requests/Request.php
+++ b/app/Http/Requests/Request.php
@@ -6,5 +6,5 @@
abstract class Request extends FormRequest {
- //
+ //
}
diff --git a/app/Http/routes.php b/app/Http/routes.php
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -14,29 +14,29 @@
|
*/
-Route::get('/', function () {
- return view('welcome');
-});
+Route::get( '/', static function () {
+ return view( 'welcome' );
+} );
// Allows to external tool to ping your instalation and know if the site is up.
-Route::get('/status', function() {
- return "ALIVE";
-});
+Route::get( '/status', static function () {
+ return "ALIVE";
+} );
// Allows to external tool to check the current configuration.
-if (Features::isEnabled('GetConfig')) {
- Route::get('/config', function() {
- $report = new ConfigReport();
- return Response::json($report);
- });
+if ( Features::isEnabled( 'GetConfig' ) ) {
+ Route::get( '/config', static function () {
+ $report = new ConfigReport();
+ return Response::json( $report );
+ } );
}
// Gate controllers
-if (Features::isEnabled('Gate')) {
- foreach (Config::get('gate.controllers') as $controller) {
- $controllerRoute = '/gate/' . $controller . '/';
- $controllerClass = "Gate\\${controller}GateController";
- Route::get($controllerRoute . '{door?}', "$controllerClass@onGet");
- Route::post($controllerRoute . '{door}', "$controllerClass@onPost");
- }
+if ( Features::isEnabled( 'Gate' ) ) {
+ foreach ( Config::get( 'gate.controllers' ) as $controller ) {
+ $controllerRoute = '/gate/' . $controller . '/';
+ $controllerClass = "Gate\\${controller}GateController";
+ Route::get( $controllerRoute . '{door?}', "$controllerClass@onGet" );
+ Route::post( $controllerRoute . '{door}', "$controllerClass@onPost" );
+ }
}
diff --git a/app/Jobs/FireDockerHubNotification.php b/app/Jobs/FireDockerHubNotification.php
--- a/app/Jobs/FireDockerHubNotification.php
+++ b/app/Jobs/FireDockerHubNotification.php
@@ -2,46 +2,44 @@
namespace Nasqueron\Notifications\Jobs;
-use Nasqueron\Notifications\Notifications\DockerHubNotification;
+use Event;
use Nasqueron\Notifications\Events\DockerHubPayloadEvent;
use Nasqueron\Notifications\Events\NotificationEvent;
-use Nasqueron\Notifications\Jobs\Job;
-
-use Event;
+use Nasqueron\Notifications\Notifications\DockerHubNotification;
class FireDockerHubNotification extends Job {
- /**
- * @var DockerHubPayloadEvent;
- */
- private $event;
-
- /**
- * Initializes a new instance of FireDockerHubNotification
- *
- * @param DockerHubPayloadEvent $event The event to notify
- */
- public function __construct (DockerHubPayloadEvent $event) {
- $this->event = $event;
- }
-
- ///
- /// Task
- ///
-
- /**
- * Executes the job.
- */
- public function handle() : void {
- $notification = $this->createNotification();
- Event::fire(new NotificationEvent($notification));
- }
-
- protected function createNotification() : DockerHubNotification {
- return new DockerHubNotification(
- $this->event->door, // project
- $this->event->event, // event type
- $this->event->payload // raw content
- );
- }
+ /**
+ * @var DockerHubPayloadEvent
+ */
+ private $event;
+
+ /**
+ * Initializes a new instance of FireDockerHubNotification
+ *
+ * @param DockerHubPayloadEvent $event The event to notify
+ */
+ public function __construct( DockerHubPayloadEvent $event ) {
+ $this->event = $event;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ */
+ public function handle(): void {
+ $notification = $this->createNotification();
+ Event::fire( new NotificationEvent( $notification ) );
+ }
+
+ protected function createNotification(): DockerHubNotification {
+ return new DockerHubNotification(
+ $this->event->door, // project
+ $this->event->event, // event type
+ $this->event->payload // raw content
+ );
+ }
}
diff --git a/app/Jobs/FireGitHubNotification.php b/app/Jobs/FireGitHubNotification.php
--- a/app/Jobs/FireGitHubNotification.php
+++ b/app/Jobs/FireGitHubNotification.php
@@ -2,47 +2,44 @@
namespace Nasqueron\Notifications\Jobs;
-use Nasqueron\Notifications\Notifications\GitHubNotification;
+use Event;
use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Nasqueron\Notifications\Events\NotificationEvent;
-use Nasqueron\Notifications\Jobs\Job;
-
-use Event;
+use Nasqueron\Notifications\Notifications\GitHubNotification;
class FireGitHubNotification extends Job {
- /**
- * @var GitHubPayloadEvent;
- */
- private $event;
-
- /**
- * Initializes a new instance of FireGitHubNotification
- *
- * @param GitHubPayloadEvent $event The event to notify
- */
- public function __construct (GitHubPayloadEvent $event) {
- $this->event = $event;
- }
-
- ///
- /// Task
- ///
-
- /**
- * Executes the job.
- */
- public function handle() : void {
- $notification = $this->createNotification();
- Event::fire(new NotificationEvent($notification));
- }
-
-
- protected function createNotification() : GitHubNotification {
- return new GitHubNotification(
- $this->event->door, // project
- $this->event->event, // event type
- $this->event->payload // raw content
- );
- }
+ /**
+ * @var GitHubPayloadEvent
+ */
+ private $event;
+
+ /**
+ * Initializes a new instance of FireGitHubNotification
+ *
+ * @param GitHubPayloadEvent $event The event to notify
+ */
+ public function __construct( GitHubPayloadEvent $event ) {
+ $this->event = $event;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ */
+ public function handle(): void {
+ $notification = $this->createNotification();
+ Event::fire( new NotificationEvent( $notification ) );
+ }
+
+ protected function createNotification(): GitHubNotification {
+ return new GitHubNotification(
+ $this->event->door, // project
+ $this->event->event, // event type
+ $this->event->payload // raw content
+ );
+ }
}
diff --git a/app/Jobs/FireJenkinsNotification.php b/app/Jobs/FireJenkinsNotification.php
--- a/app/Jobs/FireJenkinsNotification.php
+++ b/app/Jobs/FireJenkinsNotification.php
@@ -2,49 +2,47 @@
namespace Nasqueron\Notifications\Jobs;
-use Nasqueron\Notifications\Notifications\JenkinsNotification;
+use Event;
use Nasqueron\Notifications\Events\JenkinsPayloadEvent;
use Nasqueron\Notifications\Events\NotificationEvent;
-use Nasqueron\Notifications\Jobs\Job;
-
-use Event;
+use Nasqueron\Notifications\Notifications\JenkinsNotification;
class FireJenkinsNotification extends Job {
- /**
- * @var JenkinsPayloadEvent;
- */
- private $event;
-
- /**
- * Initializes a new instance of FireJenkinsNotification
- *
- * @param JenkinsPayloadEvent $event The event to notify
- */
- public function __construct (JenkinsPayloadEvent $event) {
- $this->event = $event;
- }
-
- ///
- /// Task
- ///
-
- /**
- * Executes the job.
- *
- * @return void
- */
- public function handle() : void {
- $notification = $this->createNotification();
- if ($notification->shouldNotify()) {
- Event::fire(new NotificationEvent($notification));
- }
- }
-
- protected function createNotification() : JenkinsNotification {
- return new JenkinsNotification(
- $this->event->door, // project
- $this->event->payload // raw content
- );
- }
+ /**
+ * @var JenkinsPayloadEvent
+ */
+ private $event;
+
+ /**
+ * Initializes a new instance of FireJenkinsNotification
+ *
+ * @param JenkinsPayloadEvent $event The event to notify
+ */
+ public function __construct( JenkinsPayloadEvent $event ) {
+ $this->event = $event;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ *
+ * @return void
+ */
+ public function handle(): void {
+ $notification = $this->createNotification();
+ if ( $notification->shouldNotify() ) {
+ Event::fire( new NotificationEvent( $notification ) );
+ }
+ }
+
+ protected function createNotification(): JenkinsNotification {
+ return new JenkinsNotification(
+ $this->event->door, // project
+ $this->event->payload // raw content
+ );
+ }
}
diff --git a/app/Jobs/FirePhabricatorNotification.php b/app/Jobs/FirePhabricatorNotification.php
--- a/app/Jobs/FirePhabricatorNotification.php
+++ b/app/Jobs/FirePhabricatorNotification.php
@@ -2,45 +2,43 @@
namespace Nasqueron\Notifications\Jobs;
-use Nasqueron\Notifications\Notifications\PhabricatorNotification;
-use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
-use Nasqueron\Notifications\Events\NotificationEvent;
-use Nasqueron\Notifications\Jobs\Job;
-
use Event;
+use Nasqueron\Notifications\Events\NotificationEvent;
+use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
+use Nasqueron\Notifications\Notifications\PhabricatorNotification;
class FirePhabricatorNotification extends Job {
- /**
- * @var PhabricatorPayloadEvent;
- */
- private $event;
-
- /**
- * Initializes a new instance of FirePhabricatorNotification
- *
- * @param PhabricatorPayloadEvent $event The event to notify
- */
- public function __construct (PhabricatorPayloadEvent $event) {
- $this->event = $event;
- }
-
- ///
- /// Task
- ///
-
- /**
- * Executes the job.
- */
- public function handle() : void {
- $notification = $this->createNotification();
- Event::fire(new NotificationEvent($notification));
- }
-
- protected function createNotification() : PhabricatorNotification {
- return new PhabricatorNotification(
- $this->event->door, // Project
- $this->event->story // Story
- );
- }
+ /**
+ * @var PhabricatorPayloadEvent
+ */
+ private $event;
+
+ /**
+ * Initializes a new instance of FirePhabricatorNotification
+ *
+ * @param PhabricatorPayloadEvent $event The event to notify
+ */
+ public function __construct( PhabricatorPayloadEvent $event ) {
+ $this->event = $event;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ */
+ public function handle(): void {
+ $notification = $this->createNotification();
+ Event::fire( new NotificationEvent( $notification ) );
+ }
+
+ protected function createNotification(): PhabricatorNotification {
+ return new PhabricatorNotification(
+ $this->event->door, // Project
+ $this->event->story // Story
+ );
+ }
}
diff --git a/app/Jobs/Job.php b/app/Jobs/Job.php
--- a/app/Jobs/Job.php
+++ b/app/Jobs/Job.php
@@ -6,16 +6,16 @@
abstract class Job {
- /*
- |--------------------------------------------------------------------------
- | Queueable Jobs
- |--------------------------------------------------------------------------
- |
- | This job base class provides a central location to place any logic that
- | is shared across all of your jobs. The trait included with the class
- | provides access to the "onQueue" and "delay" queue helper methods.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Queueable Jobs
+ |--------------------------------------------------------------------------
+ |
+ | This job base class provides a central location to place any logic that
+ | is shared across all of your jobs. The trait included with the class
+ | provides access to the "onQueue" and "delay" queue helper methods.
+ |
+ */
- use Queueable;
+ use Queueable;
}
diff --git a/app/Jobs/NotifyNewCommitsToDiffusion.php b/app/Jobs/NotifyNewCommitsToDiffusion.php
--- a/app/Jobs/NotifyNewCommitsToDiffusion.php
+++ b/app/Jobs/NotifyNewCommitsToDiffusion.php
@@ -2,16 +2,14 @@
namespace Nasqueron\Notifications\Jobs;
+use Event;
+use Log;
use Nasqueron\Notifications\Actions\ActionError;
use Nasqueron\Notifications\Actions\NotifyNewCommitsAction;
use Nasqueron\Notifications\Events\ReportEvent;
use Nasqueron\Notifications\Phabricator\PhabricatorAPI as API;
use Nasqueron\Notifications\Phabricator\PhabricatorAPIException;
-
-use Event;
-use Log;
use PhabricatorAPI;
-
use RuntimeException;
/**
@@ -20,182 +18,181 @@
*/
class NotifyNewCommitsToDiffusion extends Job {
- ///
- /// Private members
- ///
-
- /**
- * The clone URL of the repository
- *
- * @var string
- */
- private $repository;
-
- /**
- * @var \Nasqueron\Notifications\Phabricator\PhabricatorAPI
- */
- private $api;
-
- /**
- * @var string
- */
- private $callSign;
-
- /**
- * @var NotifyNewCommitsAction
- */
- private $actionToReport;
-
- /**
- * @var string
- */
- private $sourceProject;
-
- ///
- /// Constructor
- ///
-
- /**
- * Initializes a new instance of NotifyNewCommitsToDiffusion.
- */
- public function __construct ($sourceProject, $repository) {
- $this->sourceProject = $sourceProject;
- $this->repository = $repository;
- }
-
- ///
- /// Task
- ///
-
- /**
- * Executes the job.
- *
- * @return void
- */
- public function handle () : void {
- if (!$this->fetchRequirements()) {
- return;
- }
-
- $this->initializeReport();
- $this->notifyPhabricator();
- $this->sendReport();
- }
-
- /**
- * Initializes the actions report.
- */
- private function initializeReport () : void {
- $this->actionToReport = new NotifyNewCommitsAction($this->callSign);
- }
-
- /**
- * Notifies Phabricator to pull from the repository.
- */
- private function notifyPhabricator () : void {
- try {
- $this->callDiffusionLookSoon();
- } catch (PhabricatorAPIException $ex) {
- $actionError = new ActionError($ex);
- $this->actionToReport->attachError($actionError);
- Log::error($ex);
- }
- }
-
- /**
- * Fires a report event with the actions report.
- */
- private function sendReport () : void {
- $event = new ReportEvent($this->actionToReport);
- Event::fire($event);
- }
-
-
- ///
- /// Helper methods to find correct Phabricator instance and get the API
- ///
-
- /**
- * Gets the relevant Phabricator project for the specified source project.
- *
- * @return string The Phabricator project name
- */
- private function getPhabricatorProject () : string {
- return $this->sourceProject;
- }
-
- ///
- /// Helper methods to populate object members
- ///
-
- /**
- * Fetches API and call sign.
- *
- * @return bool true if all requirement have been fetched
- */
- private function fetchRequirements () : bool {
- return $this->fetchAPI() && $this->fetchCallSign();
- }
-
- /**
- * Fetches the Phabricator API to use for the current source project.
- *
- * @return bool true if an API instance has been fetched
- */
- private function fetchAPI () : bool {
- $project = $this->getPhabricatorProject();
-
- try {
- $this->api = PhabricatorAPI::getForProject($project);
- return true;
- } catch (RuntimeException $ex) {
- return false;
- }
- }
-
- /**
- * Fetches the call sign matching the repository.
- *
- * @return bool true if a call sign have been found ; otherwise, false.
- */
- private function fetchCallSign () : bool {
- $this->callSign = $this->getCallSign();
-
- return $this->callSign !== "";
- }
-
- ///
- /// Helper methods to query Phabricator API
- ///
-
- /**
- * Gets the call sign matching the repository URL (e.g. "OPS").
- *
- * @return string the repository call sign, or "" if not in Phabricator
- */
- private function getCallSign () : string {
- $reply = $this->api->call(
- 'repository.query',
- [ 'remoteURIs[0]' => $this->repository ]
- );
-
- if ($reply === null || !count($reply)) {
- return "";
- }
-
- return API::getFirstResult($reply)->callsign;
- }
-
- /**
- * Calls the diffusion.looksoon API method.
- *
- * @throws PhabricatorAPIException
- */
- private function callDiffusionLookSoon () : void {
- $this->api->call(
- 'diffusion.looksoon',
- [ 'callsigns[0]' => $this->callSign ]
- );
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The clone URL of the repository
+ *
+ * @var string
+ */
+ private $repository;
+
+ /**
+ * @var \Nasqueron\Notifications\Phabricator\PhabricatorAPI
+ */
+ private $api;
+
+ /**
+ * @var string
+ */
+ private $callSign;
+
+ /**
+ * @var NotifyNewCommitsAction
+ */
+ private $actionToReport;
+
+ /**
+ * @var string
+ */
+ private $sourceProject;
+
+ ///
+ /// Constructor
+ ///
+
+ /**
+ * Initializes a new instance of NotifyNewCommitsToDiffusion.
+ */
+ public function __construct( $sourceProject, $repository ) {
+ $this->sourceProject = $sourceProject;
+ $this->repository = $repository;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ *
+ * @return void
+ */
+ public function handle(): void {
+ if ( !$this->fetchRequirements() ) {
+ return;
+ }
+
+ $this->initializeReport();
+ $this->notifyPhabricator();
+ $this->sendReport();
+ }
+
+ /**
+ * Initializes the actions report.
+ */
+ private function initializeReport(): void {
+ $this->actionToReport = new NotifyNewCommitsAction( $this->callSign );
+ }
+
+ /**
+ * Notifies Phabricator to pull from the repository.
+ */
+ private function notifyPhabricator(): void {
+ try {
+ $this->callDiffusionLookSoon();
+ } catch ( PhabricatorAPIException $ex ) {
+ $actionError = new ActionError( $ex );
+ $this->actionToReport->attachError( $actionError );
+ Log::error( $ex );
+ }
+ }
+
+ /**
+ * Fires a report event with the actions report.
+ */
+ private function sendReport(): void {
+ $event = new ReportEvent( $this->actionToReport );
+ Event::fire( $event );
+ }
+
+ ///
+ /// Helper methods to find correct Phabricator instance and get the API
+ ///
+
+ /**
+ * Gets the relevant Phabricator project for the specified source project.
+ *
+ * @return string The Phabricator project name
+ */
+ private function getPhabricatorProject(): string {
+ return $this->sourceProject;
+ }
+
+ ///
+ /// Helper methods to populate object members
+ ///
+
+ /**
+ * Fetches API and call sign.
+ *
+ * @return bool true if all requirement have been fetched
+ */
+ private function fetchRequirements(): bool {
+ return $this->fetchAPI() && $this->fetchCallSign();
+ }
+
+ /**
+ * Fetches the Phabricator API to use for the current source project.
+ *
+ * @return bool true if an API instance has been fetched
+ */
+ private function fetchAPI(): bool {
+ $project = $this->getPhabricatorProject();
+
+ try {
+ $this->api = PhabricatorAPI::getForProject( $project );
+ return true;
+ } catch ( RuntimeException $ex ) {
+ return false;
+ }
+ }
+
+ /**
+ * Fetches the call sign matching the repository.
+ *
+ * @return bool true if a call sign have been found ; otherwise, false.
+ */
+ private function fetchCallSign(): bool {
+ $this->callSign = $this->getCallSign();
+
+ return $this->callSign !== "";
+ }
+
+ ///
+ /// Helper methods to query Phabricator API
+ ///
+
+ /**
+ * Gets the call sign matching the repository URL (e.g. "OPS").
+ *
+ * @return string the repository call sign, or "" if not in Phabricator
+ */
+ private function getCallSign(): string {
+ $reply = $this->api->call(
+ 'repository.query',
+ [ 'remoteURIs[0]' => $this->repository ]
+ );
+
+ if ( $reply === null || !count( $reply ) ) {
+ return "";
+ }
+
+ return API::getFirstResult( $reply )->callsign;
+ }
+
+ /**
+ * Calls the diffusion.looksoon API method.
+ *
+ * @throws PhabricatorAPIException
+ */
+ private function callDiffusionLookSoon(): void {
+ $this->api->call(
+ 'diffusion.looksoon',
+ [ 'callsigns[0]' => $this->callSign ]
+ );
+ }
}
diff --git a/app/Jobs/SendMessageToBroker.php b/app/Jobs/SendMessageToBroker.php
--- a/app/Jobs/SendMessageToBroker.php
+++ b/app/Jobs/SendMessageToBroker.php
@@ -2,112 +2,110 @@
namespace Nasqueron\Notifications\Jobs;
-use Nasqueron\Notifications\Actions\ActionError;
-use Nasqueron\Notifications\Actions\AMQPAction;
-use Nasqueron\Notifications\Events\ReportEvent;
-use Nasqueron\Notifications\Jobs\Job;
-
use Broker;
use Event;
use Log;
+use Nasqueron\Notifications\Actions\ActionError;
+use Nasqueron\Notifications\Actions\AMQPAction;
+use Nasqueron\Notifications\Events\ReportEvent;
class SendMessageToBroker extends Job {
- ///
- /// Private members
- ///
+ ///
+ /// Private members
+ ///
- /**
- * The routing key, for topic exchange
- *
- * @var string
- */
- private $routingKey = '';
+ /**
+ * The routing key, for topic exchange
+ *
+ * @var string
+ */
+ private $routingKey = '';
- /**
- * The message to send
- *
- * @var string
- */
- private $message = '';
+ /**
+ * The message to send
+ *
+ * @var string
+ */
+ private $message = '';
- /**
- * The target exchange
- *
- * @var string
- */
- private $target = '';
+ /**
+ * The target exchange
+ *
+ * @var string
+ */
+ private $target = '';
- /**
- * If not null, an exception thrown during the task
- *
- * @var \Exception
- */
- private $exception;
+ /**
+ * If not null, an exception thrown during the task
+ *
+ * @var \Exception
+ */
+ private $exception;
- ///
- /// Constructor
- ///
+ ///
+ /// Constructor
+ ///
- /**
- * Creates a new job instance.
- *
- * @param string $target The queue or exchange to send the message to
- * @param string $routingKey The routing key, for topic exchange
- * @param string $message The message to send
- *
- * @return void
- */
- public function __construct (
- string $target,
- string $routingKey,
- string $message
- ) {
- $this->target = $target;
- $this->routingKey = $routingKey;
- $this->message = $message;
- }
+ /**
+ * Creates a new job instance.
+ *
+ * @param string $target The queue or exchange to send the message to
+ * @param string $routingKey The routing key, for topic exchange
+ * @param string $message The message to send
+ *
+ * @return void
+ */
+ public function __construct(
+ string $target,
+ string $routingKey,
+ string $message
+ ) {
+ $this->target = $target;
+ $this->routingKey = $routingKey;
+ $this->message = $message;
+ }
- ///
- /// Task
- ///
+ ///
+ /// Task
+ ///
- /**
- * Executes the job.
- *
- * @return void
- */
- public function handle() : void {
- $this->sendMessage();
- $this->report();
- }
+ /**
+ * Executes the job.
+ *
+ * @return void
+ */
+ public function handle(): void {
+ $this->sendMessage();
+ $this->report();
+ }
- /**
- * Sends the message to the broker.
- */
- protected function sendMessage () : void {
- try {
- Broker::setExchangeTarget($this->target, "topic", true)
- ->routeTo($this->routingKey)
- ->sendMessage($this->message);
- } catch (\Exception $ex) {
- $this->exception = $ex;
- Log::error($ex);
- }
- }
+ /**
+ * Sends the message to the broker.
+ */
+ protected function sendMessage(): void {
+ try {
+ Broker::setExchangeTarget( $this->target, "topic", true )
+ ->routeTo( $this->routingKey )
+ ->sendMessage( $this->message );
+ } catch ( \Exception $ex ) {
+ $this->exception = $ex;
+ Log::error( $ex );
+ }
+ }
- /**
- * Prepares a report and fires a report event.
- */
- protected function report () : void {
- $actionToReport = new AMQPAction(
- "publish",
- $this->target,
- $this->routingKey
- );
- if ($this->exception !== null) {
- $actionToReport->attachError(new ActionError($this->exception));
- }
- Event::fire(new ReportEvent($actionToReport));
- }
+ /**
+ * Prepares a report and fires a report event.
+ */
+ protected function report(): void {
+ $actionToReport = new AMQPAction(
+ "publish",
+ $this->target,
+ $this->routingKey
+ );
+ if ( $this->exception !== null ) {
+ $actionToReport->attachError( new ActionError( $this->exception ) );
+ }
+ Event::fire( new ReportEvent( $actionToReport ) );
+ }
}
diff --git a/app/Jobs/TriggerDockerHubBuild.php b/app/Jobs/TriggerDockerHubBuild.php
--- a/app/Jobs/TriggerDockerHubBuild.php
+++ b/app/Jobs/TriggerDockerHubBuild.php
@@ -2,85 +2,83 @@
namespace Nasqueron\Notifications\Jobs;
-use Nasqueron\Notifications\Actions\ActionError;
-use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction;
-use Nasqueron\Notifications\Events\ReportEvent;
-
use DockerHub;
use Event;
-
use Exception;
+use Nasqueron\Notifications\Actions\ActionError;
+use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction;
+use Nasqueron\Notifications\Events\ReportEvent;
/**
* This class allows to trigger a new Docker Hub build.
*/
class TriggerDockerHubBuild extends Job {
- ///
- /// Private members
- ///
-
- /**
- * @var string The Docker image to trigger a build for
- */
- private $image;
-
- /**
- * @var TriggerDockerHubBuildAction
- */
- private $actionToReport;
-
- ///
- /// Constructor
- ///
-
- /**
- * Initializes a new instance of TriggerDockerHubBuild.
- */
- public function __construct ($image) {
- $this->image = $image;
- }
-
- ///
- /// Task
- ///
-
- /**
- * Executes the job.
- *
- * @return void
- */
- public function handle () : void {
- $this->initializeReport();
- $this->triggerBuild();
- $this->sendReport();
- }
-
- /**
- * Initializes the actions report.
- */
- private function initializeReport () : void {
- $this->actionToReport = new TriggerDockerHubBuildAction($this->image);
- }
-
- /**
- * Triggers a new Docker Hub build.
- */
- private function triggerBuild () : void {
- try {
- DockerHub::build($this->image);
- } catch (Exception $ex) {
- $actionError = new ActionError($ex);
- $this->actionToReport->attachError($actionError);
- }
- }
-
- /**
- * Fires a report event with the actions report.
- */
- private function sendReport () : void {
- $event = new ReportEvent($this->actionToReport);
- Event::fire($event);
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * @var string The Docker image to trigger a build for
+ */
+ private $image;
+
+ /**
+ * @var TriggerDockerHubBuildAction
+ */
+ private $actionToReport;
+
+ ///
+ /// Constructor
+ ///
+
+ /**
+ * Initializes a new instance of TriggerDockerHubBuild.
+ */
+ public function __construct( $image ) {
+ $this->image = $image;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ *
+ * @return void
+ */
+ public function handle(): void {
+ $this->initializeReport();
+ $this->triggerBuild();
+ $this->sendReport();
+ }
+
+ /**
+ * Initializes the actions report.
+ */
+ private function initializeReport(): void {
+ $this->actionToReport = new TriggerDockerHubBuildAction( $this->image );
+ }
+
+ /**
+ * Triggers a new Docker Hub build.
+ */
+ private function triggerBuild(): void {
+ try {
+ DockerHub::build( $this->image );
+ } catch ( Exception $ex ) {
+ $actionError = new ActionError( $ex );
+ $this->actionToReport->attachError( $actionError );
+ }
+ }
+
+ /**
+ * Fires a report event with the actions report.
+ */
+ private function sendReport(): void {
+ $event = new ReportEvent( $this->actionToReport );
+ Event::fire( $event );
+ }
}
diff --git a/app/Listeners/AMQPEventListener.php b/app/Listeners/AMQPEventListener.php
--- a/app/Listeners/AMQPEventListener.php
+++ b/app/Listeners/AMQPEventListener.php
@@ -2,71 +2,69 @@
namespace Nasqueron\Notifications\Listeners;
+use Config;
+use Illuminate\Events\Dispatcher;
use Nasqueron\Notifications\Events\NotificationEvent;
use Nasqueron\Notifications\Jobs\SendMessageToBroker;
use Nasqueron\Notifications\Notifications\Notification;
-use Illuminate\Events\Dispatcher;
-
-use Config;
-
class AMQPEventListener {
- ///
- /// Notifications
- ///
+ ///
+ /// Notifications
+ ///
- /**
- * Handles a notification event.
- *
- * @param NotificationEvent $event
- */
- public function onNotification(NotificationEvent $event) : void {
- $this->sendNotification($event->notification);
- }
+ /**
+ * Handles a notification event.
+ *
+ * @param NotificationEvent $event
+ */
+ public function onNotification( NotificationEvent $event ): void {
+ $this->sendNotification( $event->notification );
+ }
- protected static function getNotificationRoutingKey (
- Notification $notification
- ) : string {
- $keyParts = [
- $notification->project,
- $notification->group,
- $notification->service,
- $notification->type,
- ];
+ protected static function getNotificationRoutingKey(
+ Notification $notification
+ ): string {
+ $keyParts = [
+ $notification->project,
+ $notification->group,
+ $notification->service,
+ $notification->type,
+ ];
- return strtolower(implode('.', $keyParts));
- }
+ return strtolower( implode( '.', $keyParts ) );
+ }
- /**
- * Sends the notification to the broker target for distilled notifications.
- *
- * @param Notification The notification to send
- */
- protected function sendNotification(Notification $notification) : void {
- $target = Config::get('broker.targets.notifications');
- $routingKey = static::getNotificationRoutingKey($notification);
- $message = json_encode($notification);
+ /**
+ * Sends the notification to the broker target for distilled notifications.
+ *
+ * @param Notification The notification to send
+ */
+ protected function sendNotification( Notification $notification ): void {
+ $target = Config::get( 'broker.targets.notifications' );
+ $routingKey = static::getNotificationRoutingKey( $notification );
+ $message = json_encode( $notification );
- $job = new SendMessageToBroker($target, $routingKey, $message);
- $job->handle();
- }
+ $job = new SendMessageToBroker( $target, $routingKey, $message );
+ $job->handle();
+ }
- ///
- /// Events listening
- ///
+ ///
+ /// Events listening
+ ///
- /**
- * Registers the listeners for the subscriber.
- *
- * @param Dispatcher $events
- */
- public function subscribe (Dispatcher $events) : void {
- $class = AMQPEventListener::class;
- $events->listen(
- NotificationEvent::class,
- "$class@onNotification"
- );
- }
+ /**
+ * Registers the listeners for the subscriber.
+ *
+ * @param Dispatcher $events
+ */
+ public function subscribe( Dispatcher $events ): void {
+ $class = self::class;
+ $events->listen(
+ NotificationEvent::class,
+ "$class@onNotification"
+ );
+ }
}
diff --git a/app/Listeners/DockerHubListener.php b/app/Listeners/DockerHubListener.php
--- a/app/Listeners/DockerHubListener.php
+++ b/app/Listeners/DockerHubListener.php
@@ -2,80 +2,78 @@
namespace Nasqueron\Notifications\Listeners;
+use DockerHub;
+use Illuminate\Events\Dispatcher;
use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Nasqueron\Notifications\Jobs\TriggerDockerHubBuild;
-use Illuminate\Events\Dispatcher;
-
-use DockerHub;
-
/**
* Listens to events Docker Hub is interested by.
*/
class DockerHubListener {
- ///
- /// GitHub → Docker Hub
- ///
+ ///
+ /// GitHub → Docker Hub
+ ///
- /**
- * Handles payload events.
- *
- * @param GitHubPayloadEvent $event The GitHub payload event
- */
- public function onGitHubPayload (GitHubPayloadEvent $event) : void {
- if ($this->shouldNotify($event)) {
- $this->notifyNewCommits($event);
- }
- }
+ /**
+ * Handles payload events.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ */
+ public function onGitHubPayload( GitHubPayloadEvent $event ): void {
+ if ( $this->shouldNotify( $event ) ) {
+ $this->notifyNewCommits( $event );
+ }
+ }
- /**
- * Determines if the event should be notified to Docker Hub.
- * We're interested by push events, for repos with Docker images
- * we've a token to trigger a build.
- *
- * @param GitHubPayloadEvent $event The GitHub payload event
- * @return bool
- */
- public function shouldNotify (GitHubPayloadEvent $event) : bool {
- return $event->event === 'push'
- && DockerHub::hasToken($this->getRepository($event));
- }
+ /**
+ * Determines if the event should be notified to Docker Hub.
+ * We're interested by push events, for repos with Docker images
+ * we've a token to trigger a build.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ * @return bool
+ */
+ public function shouldNotify( GitHubPayloadEvent $event ): bool {
+ return $event->event === 'push'
+ && DockerHub::hasToken( $this->getRepository( $event ) );
+ }
- /**
- * Notifies Docker Hub to rebuild image.
- *
- * @param GitHubPayloadEvent $event The GitHub payload event
- */
- public function notifyNewCommits (GitHubPayloadEvent $event) : void {
- $job = new TriggerDockerHubBuild($this->getRepository($event));
- $job->handle();
- }
+ /**
+ * Notifies Docker Hub to rebuild image.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ */
+ public function notifyNewCommits( GitHubPayloadEvent $event ): void {
+ $job = new TriggerDockerHubBuild( $this->getRepository( $event ) );
+ $job->handle();
+ }
- /**
- * Extracts repository fullname (e.g. acme/foo) from event.
- *
- * @var string
- */
- private function getRepository (GitHubPayloadEvent $event) : string {
- return $event->payload->repository->full_name;
- }
+ /**
+ * Extracts repository fullname (e.g. acme/foo) from event.
+ *
+ * @var string
+ */
+ private function getRepository( GitHubPayloadEvent $event ): string {
+ return $event->payload->repository->full_name;
+ }
- ///
- /// Events listening
- ///
+ ///
+ /// Events listening
+ ///
- /**
- * Registers the listeners for the subscriber.
- *
- * @param Dispatcher $events
- */
- public function subscribe (Dispatcher $events) : void {
- $class = DockerHubListener::class;
- $events->listen(
- GitHubPayloadEvent::class,
- "$class@onGitHubPayload"
- );
- }
+ /**
+ * Registers the listeners for the subscriber.
+ *
+ * @param Dispatcher $events
+ */
+ public function subscribe( Dispatcher $events ): void {
+ $class = self::class;
+ $events->listen(
+ GitHubPayloadEvent::class,
+ "$class@onGitHubPayload"
+ );
+ }
}
diff --git a/app/Listeners/LastPayloadSaver.php b/app/Listeners/LastPayloadSaver.php
--- a/app/Listeners/LastPayloadSaver.php
+++ b/app/Listeners/LastPayloadSaver.php
@@ -5,49 +5,49 @@
use Nasqueron\Notifications\Events\Event;
class LastPayloadSaver {
- ///
- /// Events handling
- ///
-
- /**
- * Handles payload events
- */
- public function onPayload (Event $event) : void {
- self::savePayload($event->payload);
- }
-
- /**
- * Saves payload to log file
- *
- * @param mixed $payload The payload to save
- */
- public static function savePayload ($payload) : void {
- $filename = storage_path('logs/payload.json');
- $content = json_encode($payload);
- file_put_contents($filename, $content);
- }
-
- ///
- /// Events listening
- ///
-
- /**
- * Register the listeners for the subscriber.
- *
- * @param \Illuminate\Events\Dispatcher $events
- */
- public function subscribe (\Illuminate\Events\Dispatcher $events) : void {
- $ns = 'Nasqueron\Notifications\Events';
- $class = 'Nasqueron\Notifications\Listeners\LastPayloadSaver';
- $eventsToListen = [
- 'DockerHubPayloadEvent',
- 'GitHubPayloadEvent',
- 'JenkinsPayloadEvent',
- 'PhabricatorPayloadEvent',
- ];
-
- foreach ($eventsToListen as $event) {
- $events->listen("$ns\\$event", "$class@onPayload");
- }
- }
+ ///
+ /// Events handling
+ ///
+
+ /**
+ * Handles payload events
+ */
+ public function onPayload( Event $event ): void {
+ self::savePayload( $event->payload );
+ }
+
+ /**
+ * Saves payload to log file
+ *
+ * @param mixed $payload The payload to save
+ */
+ public static function savePayload( $payload ): void {
+ $filename = storage_path( 'logs/payload.json' );
+ $content = json_encode( $payload );
+ file_put_contents( $filename, $content );
+ }
+
+ ///
+ /// Events listening
+ ///
+
+ /**
+ * Register the listeners for the subscriber.
+ *
+ * @param \Illuminate\Events\Dispatcher $events
+ */
+ public function subscribe( \Illuminate\Events\Dispatcher $events ): void {
+ $ns = 'Nasqueron\Notifications\Events';
+ $class = 'Nasqueron\Notifications\Listeners\LastPayloadSaver';
+ $eventsToListen = [
+ 'DockerHubPayloadEvent',
+ 'GitHubPayloadEvent',
+ 'JenkinsPayloadEvent',
+ 'PhabricatorPayloadEvent',
+ ];
+
+ foreach ( $eventsToListen as $event ) {
+ $events->listen( "$ns\\$event", "$class@onPayload" );
+ }
+ }
}
diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php
--- a/app/Listeners/NotificationListener.php
+++ b/app/Listeners/NotificationListener.php
@@ -13,84 +13,83 @@
class NotificationListener {
- ///
- /// Distill services' payloads into notifications
- ///
+ ///
+ /// Distill services' payloads into notifications
+ ///
- /**
- * Handles a Docker Hub payload event.
- *
- * @param DockerHubPayloadEvent $event
- * @return void
- */
- public function onDockerHubPayload(DockerHubPayloadEvent $event) : void {
- $job = new FireDockerHubNotification($event);
- $job->handle();
- }
+ /**
+ * Handles a Docker Hub payload event.
+ *
+ * @param DockerHubPayloadEvent $event
+ * @return void
+ */
+ public function onDockerHubPayload( DockerHubPayloadEvent $event ): void {
+ $job = new FireDockerHubNotification( $event );
+ $job->handle();
+ }
- /**
- * Handles a GitHub payload event.
- *
- * @param GitHubPayloadEvent $event
- * @return void
- */
- public function onGitHubPayload(GitHubPayloadEvent $event) : void {
- $job = new FireGitHubNotification($event);
- $job->handle();
- }
+ /**
+ * Handles a GitHub payload event.
+ *
+ * @param GitHubPayloadEvent $event
+ * @return void
+ */
+ public function onGitHubPayload( GitHubPayloadEvent $event ): void {
+ $job = new FireGitHubNotification( $event );
+ $job->handle();
+ }
- /**
- * Handles a Phabricator payload event.
- *
- * @param PhabricatorPayloadEvent $event
- * @return void
- */
- public function onPhabricatorPayload(
- PhabricatorPayloadEvent $event
- ) : void {
- $job = new FirePhabricatorNotification($event);
- $job->handle();
- }
+ /**
+ * Handles a Phabricator payload event.
+ *
+ * @param PhabricatorPayloadEvent $event
+ * @return void
+ */
+ public function onPhabricatorPayload(
+ PhabricatorPayloadEvent $event
+ ): void {
+ $job = new FirePhabricatorNotification( $event );
+ $job->handle();
+ }
- /**
- * Handles a Jenkins payload event.
- *
- * @param JenkinsPayloadEvent $event
- * @return void
- */
- public function onJenkinsPayload (JenkinsPayloadEvent $event) : void {
- $job = new FireJenkinsNotification($event);
- $job->handle();
- }
+ /**
+ * Handles a Jenkins payload event.
+ *
+ * @param JenkinsPayloadEvent $event
+ * @return void
+ */
+ public function onJenkinsPayload( JenkinsPayloadEvent $event ): void {
+ $job = new FireJenkinsNotification( $event );
+ $job->handle();
+ }
- ///
- /// Events listening
- ///
+ ///
+ /// Events listening
+ ///
- /**
- * Register the listeners for the subscriber.
- *
- * @param \Illuminate\Events\Dispatcher $events
- */
- public function subscribe (\Illuminate\Events\Dispatcher $events) : void {
- $class = 'Nasqueron\Notifications\Listeners\NotificationListener';
- $events->listen(
- 'Nasqueron\Notifications\Events\DockerHubPayloadEvent',
- "$class@onDockerHubPayload"
- );
- $events->listen(
- 'Nasqueron\Notifications\Events\GitHubPayloadEvent',
- "$class@onGitHubPayload"
- );
- $events->listen(
- 'Nasqueron\Notifications\Events\JenkinsPayloadEvent',
- "$class@onJenkinsPayload"
- );
- $events->listen(
- 'Nasqueron\Notifications\Events\PhabricatorPayloadEvent',
- "$class@onPhabricatorPayload"
- );
-
- }
+ /**
+ * Register the listeners for the subscriber.
+ *
+ * @param \Illuminate\Events\Dispatcher $events
+ */
+ public function subscribe( \Illuminate\Events\Dispatcher $events ): void {
+ $class = 'Nasqueron\Notifications\Listeners\NotificationListener';
+ $events->listen(
+ 'Nasqueron\Notifications\Events\DockerHubPayloadEvent',
+ "$class@onDockerHubPayload"
+ );
+ $events->listen(
+ 'Nasqueron\Notifications\Events\GitHubPayloadEvent',
+ "$class@onGitHubPayload"
+ );
+ $events->listen(
+ 'Nasqueron\Notifications\Events\JenkinsPayloadEvent',
+ "$class@onJenkinsPayload"
+ );
+ $events->listen(
+ 'Nasqueron\Notifications\Events\PhabricatorPayloadEvent',
+ "$class@onPhabricatorPayload"
+ );
+ }
}
diff --git a/app/Listeners/PhabricatorListener.php b/app/Listeners/PhabricatorListener.php
--- a/app/Listeners/PhabricatorListener.php
+++ b/app/Listeners/PhabricatorListener.php
@@ -2,58 +2,57 @@
namespace Nasqueron\Notifications\Listeners;
+use Illuminate\Events\Dispatcher;
use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Nasqueron\Notifications\Jobs\NotifyNewCommitsToDiffusion;
-use Illuminate\Events\Dispatcher;
-
/**
* Listens to events Phabricator is interested by.
*/
class PhabricatorListener {
- ///
- /// GitHub → Phabricator
- ///
-
- /**
- * Handles payload events.
- *
- * @param GitHubPayloadEvent $event The GitHub payload event
- */
- public function onGitHubPayload (GitHubPayloadEvent $event) : void {
- if ($event->event === 'push') {
- $this->notifyNewCommits($event);
- }
- }
-
- /**
- * Notifies Phabricator there are new commits to pull.
- *
- * @param GitHubPayloadEvent $event The GitHub payload event
- */
- public function notifyNewCommits (GitHubPayloadEvent $event) : void {
- $job = new NotifyNewCommitsToDiffusion(
- $event->door,
- $event->payload->repository->clone_url
- );
- $job->handle();
- }
-
- ///
- /// Events listening
- ///
-
- /**
- * Registers the listeners for the subscriber.
- *
- * @param Dispatcher $events
- */
- public function subscribe (Dispatcher $events) : void {
- $class = PhabricatorListener::class;
- $events->listen(
- GitHubPayloadEvent::class,
- "$class@onGitHubPayload"
- );
- }
+ ///
+ /// GitHub → Phabricator
+ ///
+
+ /**
+ * Handles payload events.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ */
+ public function onGitHubPayload( GitHubPayloadEvent $event ): void {
+ if ( $event->event === 'push' ) {
+ $this->notifyNewCommits( $event );
+ }
+ }
+
+ /**
+ * Notifies Phabricator there are new commits to pull.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ */
+ public function notifyNewCommits( GitHubPayloadEvent $event ): void {
+ $job = new NotifyNewCommitsToDiffusion(
+ $event->door,
+ $event->payload->repository->clone_url
+ );
+ $job->handle();
+ }
+
+ ///
+ /// Events listening
+ ///
+
+ /**
+ * Registers the listeners for the subscriber.
+ *
+ * @param Dispatcher $events
+ */
+ public function subscribe( Dispatcher $events ): void {
+ $class = self::class;
+ $events->listen(
+ GitHubPayloadEvent::class,
+ "$class@onGitHubPayload"
+ );
+ }
}
diff --git a/app/Notifications/DockerHubNotification.php b/app/Notifications/DockerHubNotification.php
--- a/app/Notifications/DockerHubNotification.php
+++ b/app/Notifications/DockerHubNotification.php
@@ -2,9 +2,8 @@
namespace Nasqueron\Notifications\Notifications;
-use Nasqueron\Notifications\Analyzers\DockerHub\BaseEvent;
-
use InvalidArgumentException;
+use Nasqueron\Notifications\Analyzers\DockerHub\BaseEvent;
/**
* A Docker Hub notification.
@@ -27,65 +26,62 @@
*/
class DockerHubNotification extends Notification {
- public function __construct (
- string $project,
- string $event,
- \stdClass $payload
- ) {
- // Straightforward properties
- $this->service = "DockerHub";
- $this->project = $project;
- $this->type = $event;
- $this->rawContent = $payload;
- $this->group = "docker";
-
- // Properties from the payload
- $this->analyzeByEvent();
- }
-
- ///
- /// Analyze by event
- ///
-
- /**
- * Fills properties from event payload.
- */
- public function analyzeByEvent () : void {
- $analyzer = $this->getAnalyzer();
- $this->rawContent = $analyzer->getPayload();
- $this->text = $analyzer->getText();
- $this->link = $analyzer->getLink();
- }
-
- /**
- * Gets analyzer class name for the current event.
- *
- * @return string
- */
- private function getAnalyzerClassName () : string {
- return "Nasqueron\Notifications\Analyzers\DockerHub\\"
- . ucfirst($this->type)
- . "Event";
- }
-
- /**
- * Gets analyzer for the current event.
- *
- * @return \Nasqueron\Notifications\Analyzers\DockerHub\BaseEvent
- */
- private function getAnalyzer () : BaseEvent {
- $class = $this->getAnalyzerClassName();
-
- if (!class_exists($class)) {
- throw new InvalidArgumentException(
- "Event $this->type doesn't have a matching $class class."
- );
- }
-
- return new $class($this->rawContent);
- }
-
-
-
+ public function __construct(
+ string $project,
+ string $event,
+ \stdClass $payload
+ ) {
+ // Straightforward properties
+ $this->service = "DockerHub";
+ $this->project = $project;
+ $this->type = $event;
+ $this->rawContent = $payload;
+ $this->group = "docker";
+
+ // Properties from the payload
+ $this->analyzeByEvent();
+ }
+
+ ///
+ /// Analyze by event
+ ///
+
+ /**
+ * Fills properties from event payload.
+ */
+ public function analyzeByEvent(): void {
+ $analyzer = $this->getAnalyzer();
+ $this->rawContent = $analyzer->getPayload();
+ $this->text = $analyzer->getText();
+ $this->link = $analyzer->getLink();
+ }
+
+ /**
+ * Gets analyzer class name for the current event.
+ *
+ * @return string
+ */
+ private function getAnalyzerClassName(): string {
+ return "Nasqueron\Notifications\Analyzers\DockerHub\\"
+ . ucfirst( $this->type )
+ . "Event";
+ }
+
+ /**
+ * Gets analyzer for the current event.
+ *
+ * @return \Nasqueron\Notifications\Analyzers\DockerHub\BaseEvent
+ */
+ private function getAnalyzer(): BaseEvent {
+ $class = $this->getAnalyzerClassName();
+
+ if ( !class_exists( $class ) ) {
+ throw new InvalidArgumentException(
+ "Event $this->type doesn't have a matching $class class."
+ );
+ }
+
+ return new $class( $this->rawContent );
+ }
}
diff --git a/app/Notifications/GitHubNotification.php b/app/Notifications/GitHubNotification.php
--- a/app/Notifications/GitHubNotification.php
+++ b/app/Notifications/GitHubNotification.php
@@ -6,68 +6,68 @@
class GitHubNotification extends Notification {
- /**
- * @var GitHubPayloadAnalyzer
- */
- private $analyzer = null;
+ /**
+ * @var GitHubPayloadAnalyzer
+ */
+ private $analyzer = null;
- public function __construct (
- string $project,
- string $event,
- \stdClass $payload
- ) {
- // Straightforward properties
- $this->service = "GitHub";
- $this->project = $project;
- $this->type = $event;
- $this->rawContent = $payload;
+ public function __construct(
+ string $project,
+ string $event,
+ \stdClass $payload
+ ) {
+ // Straightforward properties
+ $this->service = "GitHub";
+ $this->project = $project;
+ $this->type = $event;
+ $this->rawContent = $payload;
- // Analyzes and fills
- $this->group = $this->getGroup();
- $this->text = $this->getText();
- $this->link = $this->getLink();
- }
+ // Analyzes and fills
+ $this->group = $this->getGroup();
+ $this->text = $this->getText();
+ $this->link = $this->getLink();
+ }
- /**
- * Gets analyzer
- */
- private function getAnalyzer () : GitHubPayloadAnalyzer {
- if ($this->analyzer === null) {
- $this->analyzer = new GitHubPayloadAnalyzer(
- $this->project,
- $this->type,
- $this->rawContent
- );
- }
- return $this->analyzer;
- }
+ /**
+ * Gets analyzer
+ */
+ private function getAnalyzer(): GitHubPayloadAnalyzer {
+ if ( $this->analyzer === null ) {
+ $this->analyzer = new GitHubPayloadAnalyzer(
+ $this->project,
+ $this->type,
+ $this->rawContent
+ );
+ }
+ return $this->analyzer;
+ }
- /**
- * Gets the target notificatrion group
- *
- * @return string the target group for the notification
- */
- public function getGroup () : string {
- return $this->getAnalyzer()->getGroup();
- }
+ /**
+ * Gets the target notificatrion group
+ *
+ * @return string the target group for the notification
+ */
+ public function getGroup(): string {
+ return $this->getAnalyzer()->getGroup();
+ }
- /**
- * Gets the notification text.
- * Intended to convey a short message (thing Twitter or IRC).
- *
- * @return string
- */
- public function getText () : string {
- return $this->getAnalyzer()->getDescription();
- }
+ /**
+ * Gets the notification text.
+ * Intended to convey a short message (thing Twitter or IRC).
+ *
+ * @return string
+ */
+ public function getText(): string {
+ return $this->getAnalyzer()->getDescription();
+ }
- /**
- * Gets the notification URL. Intended to be a widget or icon link.
- *
- * @return string
- */
- public function getLink () : string {
- return $this->getAnalyzer()->getLink();
- }
+ /**
+ * Gets the notification URL. Intended to be a widget or icon link.
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return $this->getAnalyzer()->getLink();
+ }
}
diff --git a/app/Notifications/JenkinsNotification.php b/app/Notifications/JenkinsNotification.php
--- a/app/Notifications/JenkinsNotification.php
+++ b/app/Notifications/JenkinsNotification.php
@@ -12,101 +12,101 @@
*/
class JenkinsNotification extends Notification {
- /**
- * @var \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
- */
- private $analyzer = null;
-
- /**
- * Initializes a new instance of the JenkinsNotification class.
- *
- * @param string $project The project this message is for
- * @param mixed $payload The message fired by Jenkins notification plugin
- */
- public function __construct ($project, $payload) {
- // Straightforward properties
- $this->service = "Jenkins";
- $this->project = $project;
- $this->rawContent = $payload;
-
- // Properties from the payload
- $this->group = $this->getGroup();
- $this->text = $this->getText();
- $this->link = $payload->build->full_url;
- $this->type = $this->getType();
- }
-
- /**
- * Gets the notification type.
- *
- * @return string
- */
- public function getType () : string {
- $build = $this->rawContent->build;
-
- $type = strtolower($build->phase);
-
- if (property_exists($build, 'status')) {
- $type .= '.';
- $type .= $build->status;
- }
-
- return strtolower($type);
- }
-
- /**
- * Gets the notification text. Intended to convey a short message
- * (thing Twitter or IRC).
- *
- * @return string
- */
- public function getText () : string {
- $name = $this->rawContent->name;
-
- $build = $this->rawContent->build;
- $phase = strtolower($build->phase);
-
- $text = "Jenkins job $name has been $phase";
-
- if (property_exists($build, 'status')) {
- $status = strtolower($build->status);
- $text .= ": $status";
- }
-
- return $text;
- }
-
- /**
- * Gets analyzer
- *
- * @return \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
- */
- private function getAnalyzer () : JenkinsPayloadAnalyzer {
- if ($this->analyzer === null) {
- $this->analyzer = new JenkinsPayloadAnalyzer(
- $this->project,
- $this->rawContent
- );
- }
- return $this->analyzer;
- }
-
- /**
- * Gets the notification group.
- *
- * @return string
- */
- public function getGroup () : string {
- return $this->getAnalyzer()->getGroup();
- }
-
- /**
- * Indicates if we should handle this payload to trigger a notification.
- *
- * @return bool if false, this payload is to be ignored for notifications
- */
- public function shouldNotify () : bool {
- return $this->getAnalyzer()->shouldNotify();
- }
+ /**
+ * @var \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
+ */
+ private $analyzer = null;
+
+ /**
+ * Initializes a new instance of the JenkinsNotification class.
+ *
+ * @param string $project The project this message is for
+ * @param mixed $payload The message fired by Jenkins notification plugin
+ */
+ public function __construct( $project, $payload ) {
+ // Straightforward properties
+ $this->service = "Jenkins";
+ $this->project = $project;
+ $this->rawContent = $payload;
+
+ // Properties from the payload
+ $this->group = $this->getGroup();
+ $this->text = $this->getText();
+ $this->link = $payload->build->full_url;
+ $this->type = $this->getType();
+ }
+
+ /**
+ * Gets the notification type.
+ *
+ * @return string
+ */
+ public function getType(): string {
+ $build = $this->rawContent->build;
+
+ $type = strtolower( $build->phase );
+
+ if ( property_exists( $build, 'status' ) ) {
+ $type .= '.';
+ $type .= $build->status;
+ }
+
+ return strtolower( $type );
+ }
+
+ /**
+ * Gets the notification text. Intended to convey a short message
+ * (thing Twitter or IRC).
+ *
+ * @return string
+ */
+ public function getText(): string {
+ $name = $this->rawContent->name;
+
+ $build = $this->rawContent->build;
+ $phase = strtolower( $build->phase );
+
+ $text = "Jenkins job $name has been $phase";
+
+ if ( property_exists( $build, 'status' ) ) {
+ $status = strtolower( $build->status );
+ $text .= ": $status";
+ }
+
+ return $text;
+ }
+
+ /**
+ * Gets analyzer
+ *
+ * @return \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
+ */
+ private function getAnalyzer(): JenkinsPayloadAnalyzer {
+ if ( $this->analyzer === null ) {
+ $this->analyzer = new JenkinsPayloadAnalyzer(
+ $this->project,
+ $this->rawContent
+ );
+ }
+ return $this->analyzer;
+ }
+
+ /**
+ * Gets the notification group.
+ *
+ * @return string
+ */
+ public function getGroup(): string {
+ return $this->getAnalyzer()->getGroup();
+ }
+
+ /**
+ * Indicates if we should handle this payload to trigger a notification.
+ *
+ * @return bool if false, this payload is to be ignored for notifications
+ */
+ public function shouldNotify(): bool {
+ return $this->getAnalyzer()->shouldNotify();
+ }
}
diff --git a/app/Notifications/Notification.php b/app/Notifications/Notification.php
--- a/app/Notifications/Notification.php
+++ b/app/Notifications/Notification.php
@@ -4,65 +4,65 @@
class Notification {
- ///
- /// From who?
- ///
+ ///
+ /// From who?
+ ///
- /**
- * The notification's source service (e.g. GitHub, Phabricator, Jenkins)
- *
- * @var string
- */
- public $service;
+ /**
+ * The notification's source service (e.g. GitHub, Phabricator, Jenkins)
+ *
+ * @var string
+ */
+ public $service;
- ///
- /// For whom?
- ///
+ ///
+ /// For whom?
+ ///
- /**
- * The notification's target project (e.g. Wikimedia Nasqueron, Wolfplex)
- *
- * @var string
- */
- public $project;
+ /**
+ * The notification's target project (e.g. Wikimedia Nasqueron, Wolfplex)
+ *
+ * @var string
+ */
+ public $project;
- /**
- * The notification's target group (e.g. Tasacora, Operations)
- *
- * @var string
- */
- public $group;
+ /**
+ * The notification's target group (e.g. Tasacora, Operations)
+ *
+ * @var string
+ */
+ public $group;
- ///
- /// WHAT?
- ///
+ ///
+ /// WHAT?
+ ///
- /**
- * The notification's source payload, data or message
- *
- * @var mixed
- */
- public $rawContent;
+ /**
+ * The notification's source payload, data or message
+ *
+ * @var mixed
+ */
+ public $rawContent;
- /**
- * The notification's type (e.g. "commits", "task")
- *
- * @var string
- */
- public $type;
+ /**
+ * The notification's type (e.g. "commits", "task")
+ *
+ * @var string
+ */
+ public $type;
- /**
- * The notification's text
- *
- * @var string
- */
- public $text;
+ /**
+ * The notification's text
+ *
+ * @var string
+ */
+ public $text;
- /**
- * The notification's URL, to be used as the main link for widgets
- *
- * @var string
- */
- public $link;
+ /**
+ * The notification's URL, to be used as the main link for widgets
+ *
+ * @var string
+ */
+ public $link;
}
diff --git a/app/Notifications/PhabricatorNotification.php b/app/Notifications/PhabricatorNotification.php
--- a/app/Notifications/PhabricatorNotification.php
+++ b/app/Notifications/PhabricatorNotification.php
@@ -7,61 +7,61 @@
class PhabricatorNotification extends Notification {
- /**
- * @var PhabricatorPayloadAnalyzer
- */
- private $analyzer = null;
+ /**
+ * @var PhabricatorPayloadAnalyzer
+ */
+ private $analyzer = null;
- /**
- * Initializes a new PhabricatorNotification instance
- *
- * @param string $project The project for this notification
- * @param PhabricatorStory $payload The story to convert into a notification
- */
- public function __construct (string $project, PhabricatorStory $payload) {
- // Straightforward properties
- $this->service = "Phabricator";
- $this->project = $project;
- $this->rawContent = $payload;
- $this->text = $payload->text;
+ /**
+ * Initializes a new PhabricatorNotification instance
+ *
+ * @param string $project The project for this notification
+ * @param PhabricatorStory $payload The story to convert into a notification
+ */
+ public function __construct( string $project, PhabricatorStory $payload ) {
+ // Straightforward properties
+ $this->service = "Phabricator";
+ $this->project = $project;
+ $this->rawContent = $payload;
+ $this->text = $payload->text;
- // Analyzes and fills
- $this->type = $payload->getObjectType();
- $this->group = $this->getGroup();
- $this->link = $this->getLink();
- }
+ // Analyzes and fills
+ $this->type = $payload->getObjectType();
+ $this->group = $this->getGroup();
+ $this->link = $this->getLink();
+ }
- /**
- * Gets analyzer
- *
- * @return \Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorPayloadAnalyzer
- */
- private function getAnalyzer () : PhabricatorPayloadAnalyzer {
- if ($this->analyzer === null) {
- $this->analyzer = new PhabricatorPayloadAnalyzer(
- $this->project,
- $this->rawContent
- );
- }
- return $this->analyzer;
- }
+ /**
+ * Gets analyzer
+ *
+ * @return \Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorPayloadAnalyzer
+ */
+ private function getAnalyzer(): PhabricatorPayloadAnalyzer {
+ if ( $this->analyzer === null ) {
+ $this->analyzer = new PhabricatorPayloadAnalyzer(
+ $this->project,
+ $this->rawContent
+ );
+ }
+ return $this->analyzer;
+ }
- /**
- * Gets the target notificatrion group
- *
- * @return string the target group for the notification
- */
- public function getGroup () : string {
- return $this->getAnalyzer()->getGroup();
- }
+ /**
+ * Gets the target notificatrion group
+ *
+ * @return string the target group for the notification
+ */
+ public function getGroup(): string {
+ return $this->getAnalyzer()->getGroup();
+ }
- /**
- * Gets the notification URL. Intended to be a widget or icon link.
- *
- * @return string
- */
- public function getLink () : string {
- return "";
- }
+ /**
+ * Gets the notification URL. Intended to be a widget or icon link.
+ *
+ * @return string
+ */
+ public function getLink(): string {
+ return "";
+ }
}
diff --git a/app/Phabricator/PhabricatorAPI.php b/app/Phabricator/PhabricatorAPI.php
--- a/app/Phabricator/PhabricatorAPI.php
+++ b/app/Phabricator/PhabricatorAPI.php
@@ -8,157 +8,156 @@
class PhabricatorAPI implements APIClient {
- ///
- /// Private members
- ///
-
- /**
- * The Phabricator main URL
- *
- * @var string
- */
- private $endPoint;
-
- /**
- * The token generated at /settings/panel/apitokens/ to query the API
- *
- * @var string
- */
- private $apiToken;
-
- ///
- /// Constructors
- ///
-
- /**
- * Initializes a new instance of the Phabricator API class
- *
- * @param string $endPoint The Phabricator main URL, without trailing slash
- * @param string $apiToken The token generated at /settings/panel/apitokens/
- */
- public function __construct ($endPoint, $apiToken) {
- $this->endPoint = $endPoint;
- $this->apiToken = $apiToken;
- }
-
- /**
- * @throws \RuntimeException when the service isn't in credentials.json
- */
- public static function forInstance ($instance) : PhabricatorAPI {
- $service = Services::findServiceByProperty(
- 'Phabricator',
- 'instance',
- $instance
- );
- if ($service === null) {
- throw new \RuntimeException(
- "No credentials for Phabricator instance $instance."
- );
- }
- return new self($service->instance, $service->secret);
- }
-
- /**
- * @throws \RuntimeException when the service isn't in credentials.json
- */
- public static function forProject ($project) {
- $service = Services::findServiceByDoor('Phabricator', $project);
- if ($service === null) {
- throw new \RuntimeException(
- "No credentials for Phabricator project $project."
- );
- }
- return new self($service->instance, $service->secret);
- }
-
- ///
- /// APIClient implementation
- ///
-
- /**
- * Sets API end point
- *
- * @param string $url The API end point URL
- */
- public function setEndPoint ($url) {
- $this->endPoint = $url;
- }
-
- /**
- * Calls a Conduit API method
- *
- * @param string $method The method to call (e.g. repository.create)
- * @param array $arguments The arguments to use
- * @return mixed The API result
- */
- public function call ($method, $arguments = []) {
- $url = $this->endPoint . '/api/' . $method;
- $arguments['api.token'] = $this->apiToken;
-
- $reply = json_decode(static::post($url, $arguments));
-
- if ($reply->error_code !== null) {
- throw new PhabricatorAPIException(
- $reply->error_code,
- $reply->error_info
- );
- }
-
- return $reply->result;
- }
-
- ///
- /// Helper methods
- ///
-
- /**
- * Gets the first result of an API reply.
- *
- * @param iterable $reply
- * @return mixed
- */
- public static function getFirstResult ($reply) {
- if (is_object($reply) && property_exists($reply, 'data')) {
- $reply = $reply->data;
- }
-
- foreach ($reply as $value) {
- return $value;
- }
- }
-
- ///
- /// CURL session
- ///
-
- protected static function getPostFields ($arguments) {
- $items = [];
- foreach ($arguments as $key => $value) {
- $items[] = urlencode($key) . '=' . urlencode($value);
- }
- return implode('&', $items);
- }
-
- protected static function post ($url, $arguments) {
- $options = [
- CURLOPT_URL => $url,
- CURLOPT_HEADER => false,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FOLLOWLOCATION => 1,
- CURLOPT_POSTFIELDS => static::getPostFields($arguments),
- ];
-
- $ch = curl_init();
- curl_setopt_array($ch, $options);
- $result = curl_exec($ch);
- curl_close($ch);
-
- if ($result === false) {
- throw new \RuntimeException(
- "Can't reach Phabricator API endpoint: $url"
- );
- }
-
- return $result;
- }
+ ///
+ /// Private members
+ ///
+
+ /**
+ * The Phabricator main URL
+ *
+ * @var string
+ */
+ private $endPoint;
+
+ /**
+ * The token generated at /settings/panel/apitokens/ to query the API
+ *
+ * @var string
+ */
+ private $apiToken;
+
+ ///
+ /// Constructors
+ ///
+
+ /**
+ * Initializes a new instance of the Phabricator API class
+ *
+ * @param string $endPoint The Phabricator main URL, without trailing slash
+ * @param string $apiToken The token generated at /settings/panel/apitokens/
+ */
+ public function __construct( $endPoint, $apiToken ) {
+ $this->endPoint = $endPoint;
+ $this->apiToken = $apiToken;
+ }
+
+ /**
+ * @throws \RuntimeException when the service isn't in credentials.json
+ */
+ public static function forInstance( $instance ): PhabricatorAPI {
+ $service = Services::findServiceByProperty(
+ 'Phabricator',
+ 'instance',
+ $instance
+ );
+ if ( $service === null ) {
+ throw new \RuntimeException(
+ "No credentials for Phabricator instance $instance."
+ );
+ }
+ return new self( $service->instance, $service->secret );
+ }
+
+ /**
+ * @throws \RuntimeException when the service isn't in credentials.json
+ */
+ public static function forProject( $project ) {
+ $service = Services::findServiceByDoor( 'Phabricator', $project );
+ if ( $service === null ) {
+ throw new \RuntimeException(
+ "No credentials for Phabricator project $project."
+ );
+ }
+ return new self( $service->instance, $service->secret );
+ }
+
+ ///
+ /// APIClient implementation
+ ///
+
+ /**
+ * Sets API end point
+ *
+ * @param string $url The API end point URL
+ */
+ public function setEndPoint( $url ) {
+ $this->endPoint = $url;
+ }
+
+ /**
+ * Calls a Conduit API method
+ *
+ * @param string $method The method to call (e.g. repository.create)
+ * @param array $arguments The arguments to use
+ * @return mixed The API result
+ */
+ public function call( $method, $arguments = [] ) {
+ $url = $this->endPoint . '/api/' . $method;
+ $arguments['api.token'] = $this->apiToken;
+
+ $reply = json_decode( static::post( $url, $arguments ) );
+
+ if ( $reply->error_code !== null ) {
+ throw new PhabricatorAPIException(
+ $reply->error_code,
+ $reply->error_info
+ );
+ }
+
+ return $reply->result;
+ }
+
+ ///
+ /// Helper methods
+ ///
+
+ /**
+ * Gets the first result of an API reply.
+ *
+ * @return mixed
+ */
+ public static function getFirstResult( iterable $reply ) {
+ if ( is_object( $reply ) && property_exists( $reply, 'data' ) ) {
+ $reply = $reply->data;
+ }
+
+ foreach ( $reply as $value ) {
+ return $value;
+ }
+ }
+
+ ///
+ /// CURL session
+ ///
+
+ protected static function getPostFields( $arguments ) {
+ $items = [];
+ foreach ( $arguments as $key => $value ) {
+ $items[] = urlencode( $key ) . '=' . urlencode( $value );
+ }
+ return implode( '&', $items );
+ }
+
+ protected static function post( $url, $arguments ) {
+ $options = [
+ CURLOPT_URL => $url,
+ CURLOPT_HEADER => false,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_FOLLOWLOCATION => 1,
+ CURLOPT_POSTFIELDS => static::getPostFields( $arguments ),
+ ];
+
+ $ch = curl_init();
+ curl_setopt_array( $ch, $options );
+ $result = curl_exec( $ch );
+ curl_close( $ch );
+
+ if ( $result === false ) {
+ throw new \RuntimeException(
+ "Can't reach Phabricator API endpoint: $url"
+ );
+ }
+
+ return $result;
+ }
}
diff --git a/app/Phabricator/PhabricatorAPIException.php b/app/Phabricator/PhabricatorAPIException.php
--- a/app/Phabricator/PhabricatorAPIException.php
+++ b/app/Phabricator/PhabricatorAPIException.php
@@ -3,14 +3,14 @@
namespace Nasqueron\Notifications\Phabricator;
class PhabricatorAPIException extends \RuntimeException {
-
- /**
- * @param int $code The error_code field for the API reply
- * @param string $message The error_info field from the API reply
- */
- public function __construct ($code, $message) {
- $this->code = $code;
- $this->message = $message;
- }
-
+
+ /**
+ * @param int $code The error_code field for the API reply
+ * @param string $message The error_info field from the API reply
+ */
+ public function __construct( $code, $message ) {
+ $this->code = $code;
+ $this->message = $message;
+ }
+
}
diff --git a/app/Phabricator/PhabricatorAPIFactory.php b/app/Phabricator/PhabricatorAPIFactory.php
--- a/app/Phabricator/PhabricatorAPIFactory.php
+++ b/app/Phabricator/PhabricatorAPIFactory.php
@@ -6,23 +6,23 @@
class PhabricatorAPIFactory implements APIFactory {
- /**
- * Gets an instance of the Phabricator API client class.
- *
- * @param string $instance The Phabricator instance
- * @return \Nasqueron\Notifications\Phabricator\PhabricatorAPI
- */
- public function get ($instance) {
- return PhabricatorAPI::forInstance($instance);
- }
+ /**
+ * Gets an instance of the Phabricator API client class.
+ *
+ * @param string $instance The Phabricator instance
+ * @return \Nasqueron\Notifications\Phabricator\PhabricatorAPI
+ */
+ public function get( $instance ) {
+ return PhabricatorAPI::forInstance( $instance );
+ }
- /**
- * Gets an instance of the Phabricator API client class for a project.
- *
- * @param string $project The Phabricator project name
- * @return PhabricatorAPI
- */
- public function getForProject ($project) {
- return PhabricatorAPI::forProject($project);
- }
+ /**
+ * Gets an instance of the Phabricator API client class for a project.
+ *
+ * @param string $project The Phabricator project name
+ * @return PhabricatorAPI
+ */
+ public function getForProject( string $project ) {
+ return PhabricatorAPI::forProject( $project );
+ }
}
diff --git a/app/Phabricator/PhabricatorStory.php b/app/Phabricator/PhabricatorStory.php
--- a/app/Phabricator/PhabricatorStory.php
+++ b/app/Phabricator/PhabricatorStory.php
@@ -6,326 +6,326 @@
class PhabricatorStory {
- ///
- /// Properties
- ///
-
- /**
- * The Phabricator instance name
- *
- * @var string
- */
- public $instanceName;
-
- /**
- * The unique identifier Phabricator assigns to each story
- *
- * @var int
- */
- public $id;
-
- /**
- * Type of story (e.g. PhabricatorApplicationTransactionFeedStory)
- *
- * @var string
- */
- public $type;
-
- /**
- * @var array|null
- */
- public $data;
-
- /**
- * The person logged to Phabricator and triggering the event
- *
- * @var string
- */
- public $authorPHID;
-
- /**
- * A short English textual description of the event
- *
- * @var string
- */
- public $text;
-
- /**
- * The unixtime the event occured
- *
- * @var int
- */
- public $epoch;
-
- /**
- * The projects attached to this story.
- *
- * When there is no project, [].
- * When not yet queried, null.
- *
- * @var string[]|null
- */
- private $projects = null;
-
- ///
- /// Constructors
- ///
-
- /**
- * Initializes a new instance of the Phabricator story class
- *
- * @param string $instanceName The Phabricator instance name
- */
- public function __construct ($instanceName) {
- $this->instanceName = $instanceName;
- }
-
- /**
- * Initializes a new instance of PhabricatorStory from an iterable.
- *
- * This is intended to parse the feed.hooks payloads.
- *
- * @param string $instanceName The Phabricator instance name
- * @param iterable $payload The data submitted by Phabricator
- * @return PhabricatorStory
- */
- public static function loadFromIterable (
- string $instanceName, iterable $payload
- ) {
- $instance = new self($instanceName);
-
- foreach ($payload as $key => $value) {
- $property = self::mapPhabricatorFeedKey($key);
- $instance->$property = $value;
- }
-
- return $instance;
- }
-
- public static function loadFromJson (
- $instanceName,
- $payload
- ) {
- $array = json_decode($payload, true);
-
- if (!is_array($array)) {
- throw new InvalidArgumentException(<<<MSG
+ ///
+ /// Properties
+ ///
+
+ /**
+ * The Phabricator instance name
+ *
+ * @var string
+ */
+ public $instanceName;
+
+ /**
+ * The unique identifier Phabricator assigns to each story
+ *
+ * @var int
+ */
+ public $id;
+
+ /**
+ * Type of story (e.g. PhabricatorApplicationTransactionFeedStory)
+ *
+ * @var string
+ */
+ public $type;
+
+ /**
+ * @var array|null
+ */
+ public $data;
+
+ /**
+ * The person logged to Phabricator and triggering the event
+ *
+ * @var string
+ */
+ public $authorPHID;
+
+ /**
+ * A short English textual description of the event
+ *
+ * @var string
+ */
+ public $text;
+
+ /**
+ * The unixtime the event occured
+ *
+ * @var int
+ */
+ public $epoch;
+
+ /**
+ * The projects attached to this story.
+ *
+ * When there is no project, [].
+ * When not yet queried, null.
+ *
+ * @var string[]|null
+ */
+ private $projects = null;
+
+ ///
+ /// Constructors
+ ///
+
+ /**
+ * Initializes a new instance of the Phabricator story class
+ *
+ * @param string $instanceName The Phabricator instance name
+ */
+ public function __construct( $instanceName ) {
+ $this->instanceName = $instanceName;
+ }
+
+ /**
+ * Initializes a new instance of PhabricatorStory from an iterable.
+ *
+ * This is intended to parse the feed.hooks payloads.
+ *
+ * @param string $instanceName The Phabricator instance name
+ * @param iterable $payload The data submitted by Phabricator
+ * @return PhabricatorStory
+ */
+ public static function loadFromIterable(
+ string $instanceName, iterable $payload
+ ) {
+ $instance = new self( $instanceName );
+
+ foreach ( $payload as $key => $value ) {
+ $property = self::mapPhabricatorFeedKey( $key );
+ $instance->$property = $value;
+ }
+
+ return $instance;
+ }
+
+ public static function loadFromJson(
+ $instanceName,
+ $payload
+ ) {
+ $array = json_decode( $payload, true );
+
+ if ( !is_array( $array ) ) {
+ throw new InvalidArgumentException( <<<MSG
Payload should be deserializable as an array.
MSG
);
- }
-
- return self::loadFromIterable($instanceName, $array);
- }
-
- ///
- /// Helper methods
- ///
-
- private function hasVoidObjectType () : bool {
- return $this->data === null || !isset($this->data['objectPHID']);
- }
-
- /**
- * Gets object type (e.g. TASK for PHID-TASK-l34fw5wievp6n6rnvpuk)
- *
- * @return string The object type, as a 4 letters string (e.g. 'TASK')
- */
- public function getObjectType () {
- if ($this->hasVoidObjectType()) {
- return 'VOID';
- }
-
- return substr($this->data['objectPHID'], 5, 4);
- }
-
- /**
- * Gets the identifier of the projets related to this task
- *
- * return string[] The list of project PHIDs
- */
- public function getProjectsPHIDs () {
- if (!array_key_exists('objectPHID', $this->data)) {
- return [];
- }
-
- $objectPHID = $this->data['objectPHID'];
- $objectType = $this->getObjectType();
-
- switch ($objectType) {
- case 'DREV':
- return $this->getItemProjectsPHIDs(
- 'repository.query',
- $this->getRepositoryPHID('differential.query')
- );
-
- case 'TASK':
- return $this->getItemProjectsPHIDs(
- 'maniphest.query',
- $objectPHID
- );
-
- case 'CMIT':
- return $this->getItemProjectsPHIDs(
- 'repository.query',
- $this->getRepositoryPHID('diffusion.querycommits')
- );
-
- case 'PSTE':
- return $this->getItemProjectsPHIDsThroughApplicationSearch(
- 'paste.search',
- $objectPHID
- );
-
- default:
- return [];
- }
- }
-
- /**
- * Gets the PHID of a repository
- *
- * @param string $method The API method to call (e.g. differential.query)
- * @return string The repository PHID or "" if not found
- */
- public function getRepositoryPHID ($method) {
- $objectPHID = $this->data['objectPHID'];
-
- $api = PhabricatorAPI::forProject($this->instanceName);
- $reply = $api->call(
- $method,
- [ 'phids[0]' => $objectPHID ]
- );
-
- if ($reply === []) {
- return "";
- }
-
- $apiResult = PhabricatorAPI::getFirstResult($reply);
- if ($apiResult === null) {
- // Repository information can't be fetched (T1136).
- // This occurs when the bot account used to fetch information
- // doesn't have access to the repository, for example if it's
- // in a private space or restricted to a group it doesn't belong to.
- return "";
- }
-
- return $apiResult->repositoryPHID;
- }
-
- /**
- * Gets the projects for a specific item
- *
- * @param string $method The API method to call (e.g. differential.query)
- * @param string $objectPHID The object PHID to pass as method parameter
- * @return string[] The list of project PHIDs
- */
- public function getItemProjectsPHIDs ($method, $objectPHID) {
- if (!$objectPHID) {
- return [];
- }
-
- $api = PhabricatorAPI::forProject($this->instanceName);
- $reply = $api->call(
- $method,
- [ 'phids[0]' => $objectPHID ]
- );
-
- if ($reply === []) {
- return [];
- }
-
- return PhabricatorAPI::getFirstResult($reply)->projectPHIDs;
- }
-
- /**
- * Gets the project for a specific item, using the new ApplicationSearch.
- *
- * This is a transitional method: when every Phabricator will have been
- * migrated from info (generation 1) or query (generation 2) to search
- * (generation 3), we'll rename it to getItemProjectsPHIDs and overwrite it.
- */
- protected function getItemProjectsPHIDsThroughApplicationSearch (
- $method,
- $objectPHID
- ) {
- if (!$objectPHID) {
- return [];
- }
-
- $api = PhabricatorAPI::forProject($this->instanceName);
- $reply = $api->call(
- $method,
- [
- 'constraints[phids][0]' => $objectPHID,
- 'attachments[projects]' => 1
- ]
- );
-
- $apiResult = PhabricatorAPI::getFirstResult($reply);
- if ($apiResult === null) {
- // Object information (e.g. a paste) can't be fetched (T1138).
- // This occurs when the bot account used to fetch information
- // doesn't have access to the object, for example if it's
- // in a private space or restricted to a group it doesn't belong to.
- return [];
- }
-
- return $apiResult->attachments->projects->projectPHIDs;
- }
-
- /**
- * Gets the list of the projects associated to the story
- *
- * @return string[] The list of project PHIDs
- */
- public function getProjects () {
- if ($this->projects === null) {
- $this->attachProjects();
- }
- return $this->projects;
- }
-
- /**
- * Queries the list of the projects associated to the story
- * and attached it to the projects property.
- */
- public function attachProjects () {
- $this->projects = [];
-
- $PHIDs = $this->getProjectsPHIDs();
-
- if (count($PHIDs) == 0) {
- // No project is attached to the story's object
- return;
- }
-
- $map = ProjectsMap::load($this->instanceName);
- foreach ($PHIDs as $PHID) {
- $this->projects[] = $map->getProjectName($PHID);
- }
- }
-
- ///
- /// Static helper methods
- ///
-
- /**
- * Maps a field of the API reply to a property of the PhabricatorStory class
- *
- * @param string $key The field of the API reply
- * @return string The property's name
- */
- public static function mapPhabricatorFeedKey ($key) {
- if ($key == "storyID") {
- return "id";
- }
-
- if (starts_with($key, "story") && strlen($key) > 5) {
- return lcfirst(substr($key, 5));
- }
-
- return $key;
- }
+ }
+
+ return self::loadFromIterable( $instanceName, $array );
+ }
+
+ ///
+ /// Helper methods
+ ///
+
+ private function hasVoidObjectType(): bool {
+ return $this->data === null || !isset( $this->data['objectPHID'] );
+ }
+
+ /**
+ * Gets object type (e.g. TASK for PHID-TASK-l34fw5wievp6n6rnvpuk)
+ *
+ * @return string The object type, as a 4 letters string (e.g. 'TASK')
+ */
+ public function getObjectType() {
+ if ( $this->hasVoidObjectType() ) {
+ return 'VOID';
+ }
+
+ return substr( $this->data['objectPHID'], 5, 4 );
+ }
+
+ /**
+ * Gets the identifier of the projets related to this task
+ *
+ * return string[] The list of project PHIDs
+ */
+ public function getProjectsPHIDs() {
+ if ( !array_key_exists( 'objectPHID', $this->data ) ) {
+ return [];
+ }
+
+ $objectPHID = $this->data['objectPHID'];
+ $objectType = $this->getObjectType();
+
+ switch ( $objectType ) {
+ case 'DREV':
+ return $this->getItemProjectsPHIDs(
+ 'repository.query',
+ $this->getRepositoryPHID( 'differential.query' )
+ );
+
+ case 'TASK':
+ return $this->getItemProjectsPHIDs(
+ 'maniphest.query',
+ $objectPHID
+ );
+
+ case 'CMIT':
+ return $this->getItemProjectsPHIDs(
+ 'repository.query',
+ $this->getRepositoryPHID( 'diffusion.querycommits' )
+ );
+
+ case 'PSTE':
+ return $this->getItemProjectsPHIDsThroughApplicationSearch(
+ 'paste.search',
+ $objectPHID
+ );
+
+ default:
+ return [];
+ }
+ }
+
+ /**
+ * Gets the PHID of a repository
+ *
+ * @param string $method The API method to call (e.g. differential.query)
+ * @return string The repository PHID or "" if not found
+ */
+ public function getRepositoryPHID( string $method ) {
+ $objectPHID = $this->data['objectPHID'];
+
+ $api = PhabricatorAPI::forProject( $this->instanceName );
+ $reply = $api->call(
+ $method,
+ [ 'phids[0]' => $objectPHID ]
+ );
+
+ if ( $reply === [] ) {
+ return "";
+ }
+
+ $apiResult = PhabricatorAPI::getFirstResult( $reply );
+ if ( $apiResult === null ) {
+ // Repository information can't be fetched (T1136).
+ // This occurs when the bot account used to fetch information
+ // doesn't have access to the repository, for example if it's
+ // in a private space or restricted to a group it doesn't belong to.
+ return "";
+ }
+
+ return $apiResult->repositoryPHID;
+ }
+
+ /**
+ * Gets the projects for a specific item
+ *
+ * @param string $method The API method to call (e.g. differential.query)
+ * @param string $objectPHID The object PHID to pass as method parameter
+ * @return string[] The list of project PHIDs
+ */
+ public function getItemProjectsPHIDs( string $method, string $objectPHID ) {
+ if ( !$objectPHID ) {
+ return [];
+ }
+
+ $api = PhabricatorAPI::forProject( $this->instanceName );
+ $reply = $api->call(
+ $method,
+ [ 'phids[0]' => $objectPHID ]
+ );
+
+ if ( $reply === [] ) {
+ return [];
+ }
+
+ return PhabricatorAPI::getFirstResult( $reply )->projectPHIDs;
+ }
+
+ /**
+ * Gets the project for a specific item, using the new ApplicationSearch.
+ *
+ * This is a transitional method: when every Phabricator will have been
+ * migrated from info (generation 1) or query (generation 2) to search
+ * (generation 3), we'll rename it to getItemProjectsPHIDs and overwrite it.
+ */
+ protected function getItemProjectsPHIDsThroughApplicationSearch(
+ $method,
+ $objectPHID
+ ) {
+ if ( !$objectPHID ) {
+ return [];
+ }
+
+ $api = PhabricatorAPI::forProject( $this->instanceName );
+ $reply = $api->call(
+ $method,
+ [
+ 'constraints[phids][0]' => $objectPHID,
+ 'attachments[projects]' => 1
+ ]
+ );
+
+ $apiResult = PhabricatorAPI::getFirstResult( $reply );
+ if ( $apiResult === null ) {
+ // Object information (e.g. a paste) can't be fetched (T1138).
+ // This occurs when the bot account used to fetch information
+ // doesn't have access to the object, for example if it's
+ // in a private space or restricted to a group it doesn't belong to.
+ return [];
+ }
+
+ return $apiResult->attachments->projects->projectPHIDs;
+ }
+
+ /**
+ * Gets the list of the projects associated to the story
+ *
+ * @return string[] The list of project PHIDs
+ */
+ public function getProjects() {
+ if ( $this->projects === null ) {
+ $this->attachProjects();
+ }
+ return $this->projects;
+ }
+
+ /**
+ * Queries the list of the projects associated to the story
+ * and attached it to the projects property.
+ */
+ public function attachProjects() {
+ $this->projects = [];
+
+ $PHIDs = $this->getProjectsPHIDs();
+
+ if ( count( $PHIDs ) == 0 ) {
+ // No project is attached to the story's object
+ return;
+ }
+
+ $map = ProjectsMap::load( $this->instanceName );
+ foreach ( $PHIDs as $PHID ) {
+ $this->projects[] = $map->getProjectName( $PHID );
+ }
+ }
+
+ ///
+ /// Static helper methods
+ ///
+
+ /**
+ * Maps a field of the API reply to a property of the PhabricatorStory class
+ *
+ * @param string $key The field of the API reply
+ * @return string The property's name
+ */
+ public static function mapPhabricatorFeedKey( string $key ) {
+ if ( $key == "storyID" ) {
+ return "id";
+ }
+
+ if ( str_starts_with( $key, "story" ) && strlen( $key ) > 5 ) {
+ return lcfirst( substr( $key, 5 ) );
+ }
+
+ return $key;
+ }
}
diff --git a/app/Phabricator/ProjectsMap.php b/app/Phabricator/ProjectsMap.php
--- a/app/Phabricator/ProjectsMap.php
+++ b/app/Phabricator/ProjectsMap.php
@@ -2,284 +2,283 @@
namespace Nasqueron\Notifications\Phabricator;
-use Nasqueron\Notifications\Contracts\APIClient as APIClient;
-
use App;
use Cache;
+use Nasqueron\Notifications\Contracts\APIClient as APIClient;
class ProjectsMap implements \IteratorAggregate, \ArrayAccess {
- ///
- /// Private properties and constants
- ///
-
- /**
- * The maximum number of projects to fetch
- */
- const LIMIT = 1000;
-
- /**
- * The projects as an array with phid as keys, project names as $value
- *
- * @var string[]
- */
- private $map = [];
-
- /**
- * The Phabricator instance name for this projects map
- *
- * @var string
- */
- private $instanceName;
-
- /**
- *
- * @var \Nasqueron\Notifications\Contracts\APIClient
- */
- private $apiClient;
-
- /**
- * The source of the map
- *
- * @var string
- */
- private $source = 'unloaded';
-
- ///
- /// Constructor
- ///
-
- /**
- * Initializes a new instance of ProjectsMap.
- *
- * @param string $instanceName The Phabricator instance name
- */
- public function __construct ($instanceName) {
- $this->instanceName = $instanceName;
- }
-
- ///
- /// IteratorAggregate interface implementation
- ///
-
- /**
- * Gets iterator.
- *
- * @return \Traversable
- */
- public function getIterator () {
- return new \ArrayIterator($this->map);
- }
-
- ///
- /// ArrayAccess interface implementation
- ///
-
- /**
- * Determines whether an offset exists.
- *
- * @param mixed $offset The offset
- * @return bool
- */
- public function offsetExists ($offset) {
- return array_key_exists($offset, $this->map);
- }
-
- /**
- * Gets the value at the specified offset.
- *
- * @param mixed $offset The offset.
- * @return mixed The value
- */
- public function offsetGet ($offset) {
- return $this->map[$offset];
- }
-
- /**
- * Assigns a value to the specified offset.
- *
- * @param mixed $offset The offset
- * @param mixed $value The value to assign
- */
- public function offsetSet ($offset, $value) {
- $this->map[$offset] = $value;
- }
-
- /**
- * Unsets a value at the specified offset.
- *
- * @param mixed $offset The offset where to remove the value
- */
- public function offsetUnset ($offset) {
- unset($this->map[$offset]);
- }
-
- ///
- /// Static constructors
- ///
-
- /**
- * Gets a new ProjectsMap instance from cache or API when not cached.
- *
- * @param string $phabricatorInstanceName The Phabricator instance name
- * @return ProjectsMap
- */
- public static function load ($phabricatorInstanceName) {
- $instance = new self($phabricatorInstanceName);
-
- if ($instance->isCached()) {
- $instance->loadFromCache();
- } else {
- $instance->fetchFromAPI();
- }
-
- return $instance;
- }
-
- /**
- * Gets a new ProjectsMap instance and queries Phabricator API to fill it.
- */
- public static function fetch (
- string $phabricatorInstanceName,
- ?APIClient $apiClient = null
- ) {
- $instance = new self($phabricatorInstanceName);
- $instance->setAPIClient($apiClient);
- $instance->fetchFromAPI();
- return $instance;
- }
-
- ///
- /// API
- ///
-
- /**
- * @return \Nasqueron\Notifications\Contracts\APIClient
- */
- public function getAPIClient () {
- if ($this->apiClient === null) {
- $factory = App::make('phabricator-api');
- $this->apiClient = $factory->getForProject($this->instanceName);
- }
- return $this->apiClient;
- }
-
- /**
- * @param \Nasqueron\Notifications\Contracts\APIClient|null $apiClient
- */
- public function setAPIClient (?APIClient $apiClient = null) {
- $this->apiClient = $apiClient;
- }
-
- /**
- * Fetches the projects' map from the Phabricator API.
- *
- * @throws \Exception when API reply is empty or invalid.
- */
- private function fetchFromAPI () {
- $reply = $this->getAPIClient()->call(
- 'project.query',
- [ 'limit' => self::LIMIT ]
- );
-
- if (!$reply) {
- throw new \Exception(<<<MSG
+ ///
+ /// Private properties and constants
+ ///
+
+ /**
+ * The maximum number of projects to fetch
+ */
+ const LIMIT = 1000;
+
+ /**
+ * The projects as an array with phid as keys, project names as $value
+ *
+ * @var string[]
+ */
+ private $map = [];
+
+ /**
+ * The Phabricator instance name for this projects map
+ *
+ * @var string
+ */
+ private $instanceName;
+
+ /**
+ *
+ * @var \Nasqueron\Notifications\Contracts\APIClient
+ */
+ private $apiClient;
+
+ /**
+ * The source of the map
+ *
+ * @var string
+ */
+ private $source = 'unloaded';
+
+ ///
+ /// Constructor
+ ///
+
+ /**
+ * Initializes a new instance of ProjectsMap.
+ *
+ * @param string $instanceName The Phabricator instance name
+ */
+ public function __construct( $instanceName ) {
+ $this->instanceName = $instanceName;
+ }
+
+ ///
+ /// IteratorAggregate interface implementation
+ ///
+
+ /**
+ * Gets iterator.
+ *
+ * @return \Traversable
+ */
+ public function getIterator() {
+ return new \ArrayIterator( $this->map );
+ }
+
+ ///
+ /// ArrayAccess interface implementation
+ ///
+
+ /**
+ * Determines whether an offset exists.
+ *
+ * @param mixed $offset The offset
+ * @return bool
+ */
+ public function offsetExists( $offset ) {
+ return array_key_exists( $offset, $this->map );
+ }
+
+ /**
+ * Gets the value at the specified offset.
+ *
+ * @param mixed $offset The offset.
+ * @return mixed The value
+ */
+ public function offsetGet( $offset ) {
+ return $this->map[$offset];
+ }
+
+ /**
+ * Assigns a value to the specified offset.
+ *
+ * @param mixed $offset The offset
+ * @param mixed $value The value to assign
+ */
+ public function offsetSet( $offset, $value ) {
+ $this->map[$offset] = $value;
+ }
+
+ /**
+ * Unsets a value at the specified offset.
+ *
+ * @param mixed $offset The offset where to remove the value
+ */
+ public function offsetUnset( $offset ) {
+ unset( $this->map[$offset] );
+ }
+
+ ///
+ /// Static constructors
+ ///
+
+ /**
+ * Gets a new ProjectsMap instance from cache or API when not cached.
+ *
+ * @param string $phabricatorInstanceName The Phabricator instance name
+ * @return ProjectsMap
+ */
+ public static function load( string $phabricatorInstanceName ) {
+ $instance = new self( $phabricatorInstanceName );
+
+ if ( $instance->isCached() ) {
+ $instance->loadFromCache();
+ } else {
+ $instance->fetchFromAPI();
+ }
+
+ return $instance;
+ }
+
+ /**
+ * Gets a new ProjectsMap instance and queries Phabricator API to fill it.
+ */
+ public static function fetch(
+ string $phabricatorInstanceName,
+ ?APIClient $apiClient = null
+ ) {
+ $instance = new self( $phabricatorInstanceName );
+ $instance->setAPIClient( $apiClient );
+ $instance->fetchFromAPI();
+ return $instance;
+ }
+
+ ///
+ /// API
+ ///
+
+ /**
+ * @return \Nasqueron\Notifications\Contracts\APIClient
+ */
+ public function getAPIClient() {
+ if ( $this->apiClient === null ) {
+ $factory = App::make( 'phabricator-api' );
+ $this->apiClient = $factory->getForProject( $this->instanceName );
+ }
+ return $this->apiClient;
+ }
+
+ /**
+ * @param \Nasqueron\Notifications\Contracts\APIClient|null $apiClient
+ */
+ public function setAPIClient( ?APIClient $apiClient = null ) {
+ $this->apiClient = $apiClient;
+ }
+
+ /**
+ * Fetches the projects' map from the Phabricator API.
+ *
+ * @throws \Exception when API reply is empty or invalid.
+ */
+ private function fetchFromAPI() {
+ $reply = $this->getAPIClient()->call(
+ 'project.query',
+ [ 'limit' => self::LIMIT ]
+ );
+
+ if ( !$reply ) {
+ throw new \Exception( <<<MSG
Empty reply calling project.query at $this->instanceName Conduit API.
MSG
);
- }
+ }
- if (!property_exists($reply, 'data')) {
- throw new \Exception(<<<MSG
+ if ( !property_exists( $reply, 'data' ) ) {
+ throw new \Exception( <<<MSG
Invalid reply calling project.query at $this->instanceName Conduit API.
MSG
);
- }
-
- foreach ($reply->data as $phid => $projectInfo) {
- $this->offsetSet($phid, $projectInfo->name);
- }
-
- $this->source = 'api';
- }
-
- ///
- /// Cache
- ///
-
- /**
- * Gets cache key.
- *
- * @return string The cache key for the current projects map
- */
- private function getCacheKey () {
- return class_basename(get_class($this))
- . '-'
- . md5($this->instanceName);
- }
-
- /**
- * Determines if the instance is cached
- *
- * @return bool true if cached; otherwise, false.
- */
- public function isCached () {
- return Cache::has($this->getCacheKey());
- }
-
- /**
- * Saves data to cache
- */
- public function saveToCache () {
- Cache::forever($this->getCacheKey(), $this->map);
- }
-
- /**
- * Loads data from cache
- *
- * Populates 'map' and 'source' properties
- */
- public function loadFromCache () {
- $cachedMap = Cache::get($this->getCacheKey());
- if ($cachedMap !== null) {
- $this->map = $cachedMap;
- $this->source = 'cache';
- }
- }
-
- ///
- /// Output
- ///
-
- /**
- * Gets project name, refreshing the cache if needed.
- *
- * @param string $projectPHID the PHID of the project to query the name
- * @return string The name of the poject, or an empty string if not found
- */
- public function getProjectName ($projectPHID) {
- if ($this->offsetExists($projectPHID)) {
- return $this->offsetGet($projectPHID);
- }
-
- if ($this->source !== 'api') {
- $this->fetchFromAPI();
- return $this->getProjectName($projectPHID);
- }
-
- return "";
- }
-
- /**
- * Returns the projects map as an array.
- *
- * @return array An array, each row containing ['PHID', 'project name']
- */
- public function toArray () {
- $array = [];
- foreach ($this->map as $phid => $projectName) {
- $array[] = [$phid, $projectName];
- }
- return $array;
- }
+ }
+
+ foreach ( $reply->data as $phid => $projectInfo ) {
+ $this->offsetSet( $phid, $projectInfo->name );
+ }
+
+ $this->source = 'api';
+ }
+
+ ///
+ /// Cache
+ ///
+
+ /**
+ * Gets cache key.
+ *
+ * @return string The cache key for the current projects map
+ */
+ private function getCacheKey() {
+ return class_basename( get_class( $this ) )
+ . '-'
+ . md5( $this->instanceName );
+ }
+
+ /**
+ * Determines if the instance is cached
+ *
+ * @return bool true if cached; otherwise, false.
+ */
+ public function isCached() {
+ return Cache::has( $this->getCacheKey() );
+ }
+
+ /**
+ * Saves data to cache
+ */
+ public function saveToCache() {
+ Cache::forever( $this->getCacheKey(), $this->map );
+ }
+
+ /**
+ * Loads data from cache
+ *
+ * Populates 'map' and 'source' properties
+ */
+ public function loadFromCache() {
+ $cachedMap = Cache::get( $this->getCacheKey() );
+ if ( $cachedMap !== null ) {
+ $this->map = $cachedMap;
+ $this->source = 'cache';
+ }
+ }
+
+ ///
+ /// Output
+ ///
+
+ /**
+ * Gets project name, refreshing the cache if needed.
+ *
+ * @param string $projectPHID the PHID of the project to query the name
+ * @return string The name of the poject, or an empty string if not found
+ */
+ public function getProjectName( string $projectPHID ) {
+ if ( $this->offsetExists( $projectPHID ) ) {
+ return $this->offsetGet( $projectPHID );
+ }
+
+ if ( $this->source !== 'api' ) {
+ $this->fetchFromAPI();
+ return $this->getProjectName( $projectPHID );
+ }
+
+ return "";
+ }
+
+ /**
+ * Returns the projects map as an array.
+ *
+ * @return array An array, each row containing ['PHID', 'project name']
+ */
+ public function toArray() {
+ $array = [];
+ foreach ( $this->map as $phid => $projectName ) {
+ $array[] = [ $phid, $projectName ];
+ }
+ return $array;
+ }
}
diff --git a/app/Phabricator/ProjectsMapFactory.php b/app/Phabricator/ProjectsMapFactory.php
--- a/app/Phabricator/ProjectsMapFactory.php
+++ b/app/Phabricator/ProjectsMapFactory.php
@@ -4,24 +4,24 @@
class ProjectsMapFactory {
- /**
- * Loads projects map from cache or fetches it from API if not cached.
- *
- * @param string $instanceName The Phabricator instance name
- * @return ProjectsMap
- */
- public function load ($instanceName) {
- return ProjectsMap::load($instanceName);
- }
+ /**
+ * Loads projects map from cache or fetches it from API if not cached.
+ *
+ * @param string $instanceName The Phabricator instance name
+ * @return ProjectsMap
+ */
+ public function load( string $instanceName ) {
+ return ProjectsMap::load( $instanceName );
+ }
- /**
- * Fetches projects map from API.
- *
- * @param string $instanceName The Phabricator instance name
- * @return ProjectsMap
- */
- public function fetch ($instanceName) {
- return ProjectsMap::fetch($instanceName);
- }
+ /**
+ * Fetches projects map from API.
+ *
+ * @param string $instanceName The Phabricator instance name
+ * @return ProjectsMap
+ */
+ public function fetch( string $instanceName ) {
+ return ProjectsMap::fetch( $instanceName );
+ }
}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -6,21 +6,21 @@
class AppServiceProvider extends ServiceProvider {
- /**
- * Bootstrap any application services.
- *
- * @return void
- */
- public function boot() {
- //
- }
+ /**
+ * Bootstrap any application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ //
+ }
- /**
- * Register any application services.
- *
- * @return void
- */
- public function register() {
- //
- }
+ /**
+ * Register any application services.
+ *
+ * @return void
+ */
+ public function register() {
+ //
+ }
}
diff --git a/app/Providers/BrokerServiceProvider.php b/app/Providers/BrokerServiceProvider.php
--- a/app/Providers/BrokerServiceProvider.php
+++ b/app/Providers/BrokerServiceProvider.php
@@ -9,26 +9,26 @@
class BrokerServiceProvider extends ServiceProvider {
- /**
- * Bootstraps the application services.
- *
- * @return void
- */
- public function boot() {
- }
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('broker', function (Application $app) {
- $config = $app->make('config');
- $driver = $config->get('broker.driver');
- $params = $config->get('broker.connections.' . $driver);
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'broker', static function ( Application $app ) {
+ $config = $app->make( 'config' );
+ $driver = $config->get( 'broker.driver' );
+ $params = $config->get( 'broker.connections.' . $driver );
- return BrokerFactory::make($params);
- });
- }
+ return BrokerFactory::make( $params );
+ } );
+ }
}
diff --git a/app/Providers/DockerHubServiceProvider.php b/app/Providers/DockerHubServiceProvider.php
--- a/app/Providers/DockerHubServiceProvider.php
+++ b/app/Providers/DockerHubServiceProvider.php
@@ -2,48 +2,47 @@
namespace Nasqueron\Notifications\Providers;
+use GuzzleHttp\Client;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
-
-use GuzzleHttp\Client;
use Keruald\DockerHub\Build\TriggerBuildFactory;
class DockerHubServiceProvider extends ServiceProvider {
- /**
- * Bootstraps the application services.
- *
- * @return void
- */
- public function boot() {
- }
-
- /**
- * Gets the tokens to trigger build for the Docker Hub images.
- *
- * @param \Illuminate\Contracts\Foundation\Application $app
- * @return array
- */
- public static function getTokens (Application $app) {
- $file = $app->make('config')->get('services.dockerhub.tokens');
- $fs = $app->make('filesystem')->disk('local');
-
- if ($fs->exists($file)) {
- $content = $fs->get($file);
- return json_decode($content, true);
- }
-
- return [];
- }
-
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('dockerhub', function (Application $app) {
- $tokens = DockerHubServiceProvider::getTokens($app);
- return new TriggerBuildFactory(new Client, $tokens);
- });
- }
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
+
+ /**
+ * Gets the tokens to trigger build for the Docker Hub images.
+ *
+ * @param \Illuminate\Contracts\Foundation\Application $app
+ * @return array
+ */
+ public static function getTokens( Application $app ) {
+ $file = $app->make( 'config' )->get( 'services.dockerhub.tokens' );
+ $fs = $app->make( 'filesystem' )->disk( 'local' );
+
+ if ( $fs->exists( $file ) ) {
+ $content = $fs->get( $file );
+ return json_decode( $content, true );
+ }
+
+ return [];
+ }
+
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'dockerhub', static function ( Application $app ) {
+ $tokens = DockerHubServiceProvider::getTokens( $app );
+ return new TriggerBuildFactory( new Client, $tokens );
+ } );
+ }
}
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -2,29 +2,25 @@
namespace Nasqueron\Notifications\Providers;
-use Illuminate\{
- Contracts\Events\Dispatcher as DispatcherContract,
- Foundation\Support\Providers\EventServiceProvider as ServiceProvider
-};
-
use Config;
+use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider {
- /**
- * Registers all our listeners as subscriber classes
- */
- private function subscribeListeners () {
- $this->subscribe += Config::get('app.listeners');
- }
+ /**
+ * Registers all our listeners as subscriber classes
+ */
+ private function subscribeListeners() {
+ $this->subscribe += Config::get( 'app.listeners' );
+ }
- /**
- * Register any other events for your application.
- *
- * @return void
- */
- public function boot() {
- $this->subscribeListeners();
- parent::boot();
- }
+ /**
+ * Register any other events for your application.
+ *
+ * @return void
+ */
+ public function boot() {
+ $this->subscribeListeners();
+ parent::boot();
+ }
}
diff --git a/app/Providers/MailgunServiceProvider.php b/app/Providers/MailgunServiceProvider.php
--- a/app/Providers/MailgunServiceProvider.php
+++ b/app/Providers/MailgunServiceProvider.php
@@ -2,32 +2,31 @@
namespace Nasqueron\Notifications\Providers;
+use GuzzleHttp\Client;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
-
-use GuzzleHttp\Client;
use Keruald\Mailgun\MailgunMessageFactory;
class MailgunServiceProvider extends ServiceProvider {
- /**
- * Bootstraps the application services.
- *
- * @return void
- */
- public function boot() {
- }
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('mailgun', function (Application $app) {
- $config = $app->make('config');
- $key = $config->get('services.mailgun.secret');
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'mailgun', static function ( Application $app ) {
+ $config = $app->make( 'config' );
+ $key = $config->get( 'services.mailgun.secret' );
- return new MailgunMessageFactory(new Client, $key);
- });
- }
+ return new MailgunMessageFactory( new Client, $key );
+ } );
+ }
}
diff --git a/app/Providers/PhabricatorAPIServiceProvider.php b/app/Providers/PhabricatorAPIServiceProvider.php
--- a/app/Providers/PhabricatorAPIServiceProvider.php
+++ b/app/Providers/PhabricatorAPIServiceProvider.php
@@ -8,22 +8,22 @@
class PhabricatorAPIServiceProvider extends ServiceProvider {
- /**
- * Bootstraps the application services.
- *
- * @return void
- */
- public function boot() {
- }
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('phabricator-api', function () {
- return new PhabricatorAPIFactory;
- });
- }
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'phabricator-api', static function () {
+ return new PhabricatorAPIFactory;
+ } );
+ }
}
diff --git a/app/Providers/PhabricatorProjectsMapServiceProvider.php b/app/Providers/PhabricatorProjectsMapServiceProvider.php
--- a/app/Providers/PhabricatorProjectsMapServiceProvider.php
+++ b/app/Providers/PhabricatorProjectsMapServiceProvider.php
@@ -8,22 +8,22 @@
class PhabricatorProjectsMapServiceProvider extends ServiceProvider {
- /**
- * Bootstraps the application services.
- *
- * @return void
- */
- public function boot() {
- }
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('phabricator-projectsmap', function () {
- return new ProjectsMapFactory;
- });
- }
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'phabricator-projectsmap', static function () {
+ return new ProjectsMapFactory;
+ } );
+ }
}
diff --git a/app/Providers/ReportServiceProvider.php b/app/Providers/ReportServiceProvider.php
--- a/app/Providers/ReportServiceProvider.php
+++ b/app/Providers/ReportServiceProvider.php
@@ -10,31 +10,31 @@
use Nasqueron\Notifications\Events\ReportEvent;
class ReportServiceProvider extends ServiceProvider {
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('report', function (Application $app) {
- $report = new ActionsReport();
- static::listenToActionsForReport(
- $report,
- $app->make('events')
- );
- return $report;
- });
- }
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'report', function ( Application $app ) {
+ $report = new ActionsReport();
+ static::listenToActionsForReport(
+ $report,
+ $app->make( 'events' )
+ );
+ return $report;
+ } );
+ }
- public static function listenToActionsForReport (
- ActionsReport $report,
- Dispatcher $events
- ) {
- $events->listen(
- 'Nasqueron\Notifications\Events\ReportEvent',
- function (ReportEvent $event) use ($report) {
- $report->addAction($event->action);
- }
- );
- }
+ public static function listenToActionsForReport(
+ ActionsReport $report,
+ Dispatcher $events
+ ) {
+ $events->listen(
+ 'Nasqueron\Notifications\Events\ReportEvent',
+ static function ( ReportEvent $event ) use ( $report ) {
+ $report->addAction( $event->action );
+ }
+ );
+ }
}
diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php
--- a/app/Providers/RouteServiceProvider.php
+++ b/app/Providers/RouteServiceProvider.php
@@ -2,42 +2,40 @@
namespace Nasqueron\Notifications\Providers;
-use Illuminate\{
- Routing\Router,
- Foundation\Support\Providers\RouteServiceProvider as ServiceProvider
-};
+use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
+use Illuminate\Routing\Router;
class RouteServiceProvider extends ServiceProvider {
- /**
- * This namespace is applied to the controller routes in your routes file.
- *
- * In addition, it is set as the URL generator's root namespace.
- *
- * @var string
- */
- protected $namespace = 'Nasqueron\Notifications\Http\Controllers';
+ /**
+ * This namespace is applied to the controller routes in your routes file.
+ *
+ * In addition, it is set as the URL generator's root namespace.
+ *
+ * @var string
+ */
+ protected $namespace = 'Nasqueron\Notifications\Http\Controllers';
- /**
- * Define your route model bindings, pattern filters, etc.
- *
- * @return void
- */
- public function boot() {
- //
+ /**
+ * Define your route model bindings, pattern filters, etc.
+ *
+ * @return void
+ */
+ public function boot() {
+ //
- parent::boot();
- }
+ parent::boot();
+ }
- /**
- * Define the routes for the application.
- *
- * @param \Illuminate\Routing\Router $router
- * @return void
- */
- public function map(Router $router) {
- $router->group(['namespace' => $this->namespace], function ($router) {
- require app_path('Http/routes.php');
- });
- }
+ /**
+ * Define the routes for the application.
+ *
+ * @param \Illuminate\Routing\Router $router
+ * @return void
+ */
+ public function map( Router $router ) {
+ $router->group( [ 'namespace' => $this->namespace ], static function ( $router ) {
+ require app_path( 'Http/routes.php' );
+ } );
+ }
}
diff --git a/app/Providers/SentryServiceProvider.php b/app/Providers/SentryServiceProvider.php
--- a/app/Providers/SentryServiceProvider.php
+++ b/app/Providers/SentryServiceProvider.php
@@ -7,24 +7,24 @@
class SentryServiceProvider extends ServiceProvider {
- /**
- * Bootstraps the application services.
- *
- * @return void
- */
- public function boot() {
- }
+ /**
+ * Bootstraps the application services.
+ *
+ * @return void
+ */
+ public function boot() {
+ }
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('raven', function (Application $app) {
- $config = $app->make('config');
- $dsn = $config->get('services.sentry.dsn');
- return new \Raven_Client($dsn);
- });
- }
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'raven', static function ( Application $app ) {
+ $config = $app->make( 'config' );
+ $dsn = $config->get( 'services.sentry.dsn' );
+ return new \Raven_Client( $dsn );
+ } );
+ }
}
diff --git a/app/Providers/ServicesServiceProvider.php b/app/Providers/ServicesServiceProvider.php
--- a/app/Providers/ServicesServiceProvider.php
+++ b/app/Providers/ServicesServiceProvider.php
@@ -8,19 +8,19 @@
use Nasqueron\Notifications\Config\Services\Services;
class ServicesServiceProvider extends ServiceProvider {
- /**
- * Registers the application services.
- *
- * @return void
- */
- public function register() {
- $this->app->singleton('services', function (Application $app) {
- $path = config('services.gate.credentials');
- if (strlen($path) > 0 && $app->make('filesystem')->has($path)) {
- return Services::loadFromJson($path);
- }
+ /**
+ * Registers the application services.
+ *
+ * @return void
+ */
+ public function register() {
+ $this->app->singleton( 'services', static function ( Application $app ) {
+ $path = config( 'services.gate.credentials' );
+ if ( strlen( $path ) > 0 && $app->make( 'filesystem' )->has( $path ) ) {
+ return Services::loadFromJson( $path );
+ }
- return new Services;
- });
- }
+ return new Services;
+ } );
+ }
}
diff --git a/bootstrap/app.php b/bootstrap/app.php
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -12,7 +12,7 @@
*/
$app = new Illuminate\Foundation\Application(
- realpath(__DIR__.'/../')
+ realpath( __DIR__ . '/../' )
);
/*
@@ -27,18 +27,18 @@
*/
$app->singleton(
- Illuminate\Contracts\Http\Kernel::class,
- Nasqueron\Notifications\Http\Kernel::class
+ Illuminate\Contracts\Http\Kernel::class,
+ Nasqueron\Notifications\Http\Kernel::class
);
$app->singleton(
- Illuminate\Contracts\Console\Kernel::class,
- Nasqueron\Notifications\Console\Kernel::class
+ Illuminate\Contracts\Console\Kernel::class,
+ Nasqueron\Notifications\Console\Kernel::class
);
$app->singleton(
- Illuminate\Contracts\Debug\ExceptionHandler::class,
- Nasqueron\Notifications\Exceptions\Handler::class
+ Illuminate\Contracts\Debug\ExceptionHandler::class,
+ Nasqueron\Notifications\Exceptions\Handler::class
);
/*
diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php
--- a/bootstrap/autoload.php
+++ b/bootstrap/autoload.php
@@ -1,6 +1,6 @@
<?php
-define('LARAVEL_START', microtime(true));
+define( 'LARAVEL_START', microtime( true ) );
/*
|--------------------------------------------------------------------------
@@ -14,7 +14,7 @@
|
*/
-require __DIR__.'/../vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
@@ -27,8 +27,8 @@
|
*/
-$compiledPath = __DIR__.'/cache/compiled.php';
+$compiledPath = __DIR__ . '/cache/compiled.php';
-if (file_exists($compiledPath)) {
- require $compiledPath;
+if ( file_exists( $compiledPath ) ) {
+ require $compiledPath;
}
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -10,8 +10,8 @@
"license": "BSD-2-Clause",
"type": "project",
"require": {
- "php": ">=7.1.0",
- "laravel/framework": "5.3.*",
+ "php": ">=8.1.0",
+ "laravel/framework": "8.*",
"guzzlehttp/guzzle": "^6.2",
"keruald/dockerhub": "^0.0.3",
"keruald/github": "^0.2.1",
@@ -23,16 +23,16 @@
"require-dev": {
"phan/phan": "^3.2.2",
"fzaninotto/faker": "~1.4",
- "mockery/mockery": "0.9.*",
- "pdepend/pdepend": "^2.4.1",
- "phploc/phploc": "^3.0.1",
- "phpmd/phpmd" : "@stable",
- "phpunit/phpunit": "~5.4",
- "phpspec/phpspec": "~2.1",
- "sebastian/phpcpd": "^2.0.4",
- "squizlabs/php_codesniffer": "2.*",
+ "mockery/mockery": "^1.5.0",
+ "phpunit/phpunit": "~8.0",
+ "squizlabs/php_codesniffer": "^3.6.2",
"symfony/css-selector": "~3.0",
- "symfony/dom-crawler": "~3.0"
+ "symfony/dom-crawler": "~3.0",
+ "rector/rector": "^0.12.21",
+ "pdepend/pdepend": "^2.10",
+ "phpmd/phpmd": "^2.12",
+ "phpspec/phpspec": "^7.2",
+ "nasqueron/codestyle": "^0.1.0"
},
"autoload": {
"psr-4": {
@@ -48,13 +48,16 @@
"php artisan key:generate"
],
"phpmd": [
- "vendor/bin/phpmd app/ xml ruleset.xml"
+ "vendor/bin/phpmd app/ xml phpcs.xml"
],
"test": [
"phpunit --no-coverage"
]
},
"config": {
- "preferred-install": "dist"
+ "preferred-install": "dist",
+ "allow-plugins": {
+ "kylekatarnls/update-helper": true
+ }
}
}
diff --git a/config/app.php b/config/app.php
--- a/config/app.php
+++ b/config/app.php
@@ -2,281 +2,281 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Application Name
- |--------------------------------------------------------------------------
- |
- | This value is the name of your application. This value is used when the
- | framework needs to place the application's name in a notification or
- | any other location as required by the application or its packages.
- */
-
- 'name' => 'Notifications',
-
- /*
- |--------------------------------------------------------------------------
- | Application Environment
- |--------------------------------------------------------------------------
- |
- | This value determines the "environment" your application is currently
- | running in. This may determine how you prefer to configure various
- | services your application utilizes. Set this in your ".env" file.
- |
- */
-
- 'env' => env('APP_ENV', 'production'),
-
- /*
- |--------------------------------------------------------------------------
- | Application Debug Mode
- |--------------------------------------------------------------------------
- |
- | When your application is in debug mode, detailed error messages with
- | stack traces will be shown on every error that occurs within your
- | application. If disabled, a simple generic error page is shown.
- |
- */
-
- 'debug' => env('APP_DEBUG', false),
-
- /*
- |--------------------------------------------------------------------------
- | Application URL
- |--------------------------------------------------------------------------
- |
- | This URL is used by the console to properly generate URLs when using
- | the Artisan command line tool. You should set this to the root of
- | your application so that it is used when running Artisan tasks.
- |
- */
-
- 'url' => 'http://localhost',
-
- /*
- |--------------------------------------------------------------------------
- | Application Timezone
- |--------------------------------------------------------------------------
- |
- | Here you may specify the default timezone for your application, which
- | will be used by the PHP date and date-time functions. We have gone
- | ahead and set this to a sensible default for you out of the box.
- |
- */
-
- 'timezone' => 'UTC',
-
- /*
- |--------------------------------------------------------------------------
- | Application Locale Configuration
- |--------------------------------------------------------------------------
- |
- | The application locale determines the default locale that will be used
- | by the translation service provider. You are free to set this value
- | to any of the locales which will be supported by the application.
- |
- */
-
- 'locale' => 'en',
-
- /*
- |--------------------------------------------------------------------------
- | Application Fallback Locale
- |--------------------------------------------------------------------------
- |
- | The fallback locale determines the locale to use when the current one
- | is not available. You may change the value to correspond to any of
- | the language folders that are provided through your application.
- |
- */
-
- 'fallback_locale' => 'en',
-
- /*
- |--------------------------------------------------------------------------
- | Encryption Key
- |--------------------------------------------------------------------------
- |
- | This key is used by the Illuminate encrypter service and should be set
- | to a random, 32 character string, otherwise these encrypted strings
- | will not be safe. Please do this before deploying an application!
- |
- */
-
- 'key' => env('APP_KEY'),
-
- 'cipher' => 'AES-256-CBC',
-
- /*
- |--------------------------------------------------------------------------
- | Logging Configuration
- |--------------------------------------------------------------------------
- |
- | Here you may configure the log settings for your application. Out of
- | the box, Laravel uses the Monolog PHP logging library. This gives
- | you a variety of powerful log handlers / formatters to utilize.
- |
- | Available Settings: "single", "daily", "syslog", "errorlog"
- |
- */
-
- 'log' => env('APP_LOG', 'single'),
-
- /*
- |--------------------------------------------------------------------------
- | Features
- |--------------------------------------------------------------------------
- |
- | This array contains the features provided by the notifications center.
- |
- | It allows to toggle a feature on the fly, with a boolean to enable it.
- |
- */
-
- 'features' => [
- // Enable the API entry point at the /gate URL
- 'Gate' => true,
-
- // Enable the configuration report entry point at the /config URL
- 'GetConfig' => true,
-
- // Send a response to inform the caller of the different actions done.
- // If disabled, send an empty 200 response instead.
- 'ActionsReport' => true,
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Autoloaded Service Providers
- |--------------------------------------------------------------------------
- |
- | The service providers listed here will be automatically loaded on the
- | request to your application. Feel free to add your own services to
- | this array to grant expanded functionality to your applications.
- |
- */
-
- 'providers' => [
-
- /*
- * Laravel Framework Service Providers...
- */
- Illuminate\Broadcasting\BroadcastServiceProvider::class,
- Illuminate\Bus\BusServiceProvider::class,
- Illuminate\Cache\CacheServiceProvider::class,
- Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
- Illuminate\Cookie\CookieServiceProvider::class,
- Illuminate\Database\DatabaseServiceProvider::class,
- Illuminate\Encryption\EncryptionServiceProvider::class,
- Illuminate\Filesystem\FilesystemServiceProvider::class,
- Illuminate\Foundation\Providers\FoundationServiceProvider::class,
- Illuminate\Hashing\HashServiceProvider::class,
- Illuminate\Mail\MailServiceProvider::class,
- Illuminate\Pagination\PaginationServiceProvider::class,
- Illuminate\Pipeline\PipelineServiceProvider::class,
- Illuminate\Queue\QueueServiceProvider::class,
- Illuminate\Redis\RedisServiceProvider::class,
- Illuminate\Session\SessionServiceProvider::class,
- Illuminate\Translation\TranslationServiceProvider::class,
- Illuminate\Validation\ValidationServiceProvider::class,
- Illuminate\View\ViewServiceProvider::class,
-
- /*
- * Application Service Providers...
- */
- Nasqueron\Notifications\Providers\AppServiceProvider::class,
- Nasqueron\Notifications\Providers\BrokerServiceProvider::class,
- Nasqueron\Notifications\Providers\DockerHubServiceProvider::class,
- Nasqueron\Notifications\Providers\EventServiceProvider::class,
- Nasqueron\Notifications\Providers\MailgunServiceProvider::class,
- Nasqueron\Notifications\Providers\PhabricatorAPIServiceProvider::class,
- Nasqueron\Notifications\Providers\PhabricatorProjectsMapServiceProvider::class,
- Nasqueron\Notifications\Providers\ReportServiceProvider::class,
- Nasqueron\Notifications\Providers\RouteServiceProvider::class,
- Nasqueron\Notifications\Providers\SentryServiceProvider::class,
- Nasqueron\Notifications\Providers\ServicesServiceProvider::class
-
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Events listeners
- |--------------------------------------------------------------------------
- |
- | The events listeners listed here will be automatically loaded on the
- | request to your application.
- |
- */
-
- 'listeners' => [
- Nasqueron\Notifications\Listeners\AMQPEventListener::class,
- Nasqueron\Notifications\Listeners\DockerHubListener::class,
- Nasqueron\Notifications\Listeners\LastPayloadSaver::class,
- Nasqueron\Notifications\Listeners\NotificationListener::class,
- Nasqueron\Notifications\Listeners\PhabricatorListener::class,
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Class Aliases
- |--------------------------------------------------------------------------
- |
- | This array of class aliases will be registered when this application
- | is started. However, feel free to register as many as you wish as
- | the aliases are "lazy" loaded so they don't hinder performance.
- |
- */
-
- 'aliases' => [
- /*
- * Laravel Framework aliases...
- */
- 'App' => Illuminate\Support\Facades\App::class,
- 'Artisan' => Illuminate\Support\Facades\Artisan::class,
- 'Auth' => Illuminate\Support\Facades\Auth::class,
- 'Blade' => Illuminate\Support\Facades\Blade::class,
- 'Bus' => Illuminate\Support\Facades\Bus::class,
- 'Cache' => Illuminate\Support\Facades\Cache::class,
- 'Config' => Illuminate\Support\Facades\Config::class,
- 'Cookie' => Illuminate\Support\Facades\Cookie::class,
- 'Crypt' => Illuminate\Support\Facades\Crypt::class,
- 'DB' => Illuminate\Support\Facades\DB::class,
- 'Eloquent' => Illuminate\Database\Eloquent\Model::class,
- 'Event' => Illuminate\Support\Facades\Event::class,
- 'File' => Illuminate\Support\Facades\File::class,
- 'Gate' => Illuminate\Support\Facades\Gate::class,
- 'Hash' => Illuminate\Support\Facades\Hash::class,
- 'Input' => Illuminate\Support\Facades\Input::class,
- 'Inspiring' => Illuminate\Foundation\Inspiring::class,
- 'Lang' => Illuminate\Support\Facades\Lang::class,
- 'Log' => Illuminate\Support\Facades\Log::class,
- 'Mail' => Illuminate\Support\Facades\Mail::class,
- 'Password' => Illuminate\Support\Facades\Password::class,
- 'Queue' => Illuminate\Support\Facades\Queue::class,
- 'Redirect' => Illuminate\Support\Facades\Redirect::class,
- 'Redis' => Illuminate\Support\Facades\Redis::class,
- 'Request' => Illuminate\Support\Facades\Request::class,
- 'Response' => Illuminate\Support\Facades\Response::class,
- 'Route' => Illuminate\Support\Facades\Route::class,
- 'Schema' => Illuminate\Support\Facades\Schema::class,
- 'Session' => Illuminate\Support\Facades\Session::class,
- 'Storage' => Illuminate\Support\Facades\Storage::class,
- 'URL' => Illuminate\Support\Facades\URL::class,
- 'Validator' => Illuminate\Support\Facades\Validator::class,
- 'View' => Illuminate\Support\Facades\View::class,
-
- /*
- * App aliases...
- */
- 'Broker' => Nasqueron\Notifications\Facades\Broker::class,
- 'DockerHub' => Nasqueron\Notifications\Facades\DockerHub::class,
- 'Mailgun' => Nasqueron\Notifications\Facades\Mailgun::class,
- 'PhabricatorAPI' => Nasqueron\Notifications\Facades\PhabricatorAPI::class,
- 'ProjectsMap' => Nasqueron\Notifications\Facades\ProjectsMap::class,
- 'Raven' => Nasqueron\Notifications\Facades\Raven::class,
- 'Report' => Nasqueron\Notifications\Facades\Report::class,
- 'Services' => Nasqueron\Notifications\Facades\Services::class,
-
- ],
+ /*
+ |--------------------------------------------------------------------------
+ | Application Name
+ |--------------------------------------------------------------------------
+ |
+ | This value is the name of your application. This value is used when the
+ | framework needs to place the application's name in a notification or
+ | any other location as required by the application or its packages.
+ */
+
+ 'name' => 'Notifications',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Environment
+ |--------------------------------------------------------------------------
+ |
+ | This value determines the "environment" your application is currently
+ | running in. This may determine how you prefer to configure various
+ | services your application utilizes. Set this in your ".env" file.
+ |
+ */
+
+ 'env' => env( 'APP_ENV', 'production' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Debug Mode
+ |--------------------------------------------------------------------------
+ |
+ | When your application is in debug mode, detailed error messages with
+ | stack traces will be shown on every error that occurs within your
+ | application. If disabled, a simple generic error page is shown.
+ |
+ */
+
+ 'debug' => env( 'APP_DEBUG', false ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application URL
+ |--------------------------------------------------------------------------
+ |
+ | This URL is used by the console to properly generate URLs when using
+ | the Artisan command line tool. You should set this to the root of
+ | your application so that it is used when running Artisan tasks.
+ |
+ */
+
+ 'url' => 'http://localhost',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Timezone
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify the default timezone for your application, which
+ | will be used by the PHP date and date-time functions. We have gone
+ | ahead and set this to a sensible default for you out of the box.
+ |
+ */
+
+ 'timezone' => 'UTC',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Locale Configuration
+ |--------------------------------------------------------------------------
+ |
+ | The application locale determines the default locale that will be used
+ | by the translation service provider. You are free to set this value
+ | to any of the locales which will be supported by the application.
+ |
+ */
+
+ 'locale' => 'en',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Fallback Locale
+ |--------------------------------------------------------------------------
+ |
+ | The fallback locale determines the locale to use when the current one
+ | is not available. You may change the value to correspond to any of
+ | the language folders that are provided through your application.
+ |
+ */
+
+ 'fallback_locale' => 'en',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Encryption Key
+ |--------------------------------------------------------------------------
+ |
+ | This key is used by the Illuminate encrypter service and should be set
+ | to a random, 32 character string, otherwise these encrypted strings
+ | will not be safe. Please do this before deploying an application!
+ |
+ */
+
+ 'key' => env( 'APP_KEY' ),
+
+ 'cipher' => 'AES-256-CBC',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Logging Configuration
+ |--------------------------------------------------------------------------
+ |
+ | Here you may configure the log settings for your application. Out of
+ | the box, Laravel uses the Monolog PHP logging library. This gives
+ | you a variety of powerful log handlers / formatters to utilize.
+ |
+ | Available Settings: "single", "daily", "syslog", "errorlog"
+ |
+ */
+
+ 'log' => env( 'APP_LOG', 'single' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Features
+ |--------------------------------------------------------------------------
+ |
+ | This array contains the features provided by the notifications center.
+ |
+ | It allows to toggle a feature on the fly, with a boolean to enable it.
+ |
+ */
+
+ 'features' => [
+ // Enable the API entry point at the /gate URL
+ 'Gate' => true,
+
+ // Enable the configuration report entry point at the /config URL
+ 'GetConfig' => true,
+
+ // Send a response to inform the caller of the different actions done.
+ // If disabled, send an empty 200 response instead.
+ 'ActionsReport' => true,
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Autoloaded Service Providers
+ |--------------------------------------------------------------------------
+ |
+ | The service providers listed here will be automatically loaded on the
+ | request to your application. Feel free to add your own services to
+ | this array to grant expanded functionality to your applications.
+ |
+ */
+
+ 'providers' => [
+
+ /*
+ * Laravel Framework Service Providers...
+ */
+ Illuminate\Broadcasting\BroadcastServiceProvider::class,
+ Illuminate\Bus\BusServiceProvider::class,
+ Illuminate\Cache\CacheServiceProvider::class,
+ Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
+ Illuminate\Cookie\CookieServiceProvider::class,
+ Illuminate\Database\DatabaseServiceProvider::class,
+ Illuminate\Encryption\EncryptionServiceProvider::class,
+ Illuminate\Filesystem\FilesystemServiceProvider::class,
+ Illuminate\Foundation\Providers\FoundationServiceProvider::class,
+ Illuminate\Hashing\HashServiceProvider::class,
+ Illuminate\Mail\MailServiceProvider::class,
+ Illuminate\Pagination\PaginationServiceProvider::class,
+ Illuminate\Pipeline\PipelineServiceProvider::class,
+ Illuminate\Queue\QueueServiceProvider::class,
+ Illuminate\Redis\RedisServiceProvider::class,
+ Illuminate\Session\SessionServiceProvider::class,
+ Illuminate\Translation\TranslationServiceProvider::class,
+ Illuminate\Validation\ValidationServiceProvider::class,
+ Illuminate\View\ViewServiceProvider::class,
+
+ /*
+ * Application Service Providers...
+ */
+ Nasqueron\Notifications\Providers\AppServiceProvider::class,
+ Nasqueron\Notifications\Providers\BrokerServiceProvider::class,
+ Nasqueron\Notifications\Providers\DockerHubServiceProvider::class,
+ Nasqueron\Notifications\Providers\EventServiceProvider::class,
+ Nasqueron\Notifications\Providers\MailgunServiceProvider::class,
+ Nasqueron\Notifications\Providers\PhabricatorAPIServiceProvider::class,
+ Nasqueron\Notifications\Providers\PhabricatorProjectsMapServiceProvider::class,
+ Nasqueron\Notifications\Providers\ReportServiceProvider::class,
+ Nasqueron\Notifications\Providers\RouteServiceProvider::class,
+ Nasqueron\Notifications\Providers\SentryServiceProvider::class,
+ Nasqueron\Notifications\Providers\ServicesServiceProvider::class
+
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Events listeners
+ |--------------------------------------------------------------------------
+ |
+ | The events listeners listed here will be automatically loaded on the
+ | request to your application.
+ |
+ */
+
+ 'listeners' => [
+ Nasqueron\Notifications\Listeners\AMQPEventListener::class,
+ Nasqueron\Notifications\Listeners\DockerHubListener::class,
+ Nasqueron\Notifications\Listeners\LastPayloadSaver::class,
+ Nasqueron\Notifications\Listeners\NotificationListener::class,
+ Nasqueron\Notifications\Listeners\PhabricatorListener::class,
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Class Aliases
+ |--------------------------------------------------------------------------
+ |
+ | This array of class aliases will be registered when this application
+ | is started. However, feel free to register as many as you wish as
+ | the aliases are "lazy" loaded so they don't hinder performance.
+ |
+ */
+
+ 'aliases' => [
+ /*
+ * Laravel Framework aliases...
+ */
+ 'App' => Illuminate\Support\Facades\App::class,
+ 'Artisan' => Illuminate\Support\Facades\Artisan::class,
+ 'Auth' => Illuminate\Support\Facades\Auth::class,
+ 'Blade' => Illuminate\Support\Facades\Blade::class,
+ 'Bus' => Illuminate\Support\Facades\Bus::class,
+ 'Cache' => Illuminate\Support\Facades\Cache::class,
+ 'Config' => Illuminate\Support\Facades\Config::class,
+ 'Cookie' => Illuminate\Support\Facades\Cookie::class,
+ 'Crypt' => Illuminate\Support\Facades\Crypt::class,
+ 'DB' => Illuminate\Support\Facades\DB::class,
+ 'Eloquent' => Illuminate\Database\Eloquent\Model::class,
+ 'Event' => Illuminate\Support\Facades\Event::class,
+ 'File' => Illuminate\Support\Facades\File::class,
+ 'Gate' => Illuminate\Support\Facades\Gate::class,
+ 'Hash' => Illuminate\Support\Facades\Hash::class,
+ 'Input' => \Illuminate\Support\Facades\Request::class,
+ 'Inspiring' => Illuminate\Foundation\Inspiring::class,
+ 'Lang' => Illuminate\Support\Facades\Lang::class,
+ 'Log' => Illuminate\Support\Facades\Log::class,
+ 'Mail' => Illuminate\Support\Facades\Mail::class,
+ 'Password' => Illuminate\Support\Facades\Password::class,
+ 'Queue' => Illuminate\Support\Facades\Queue::class,
+ 'Redirect' => Illuminate\Support\Facades\Redirect::class,
+ 'Redis' => Illuminate\Support\Facades\Redis::class,
+ 'Request' => Illuminate\Support\Facades\Request::class,
+ 'Response' => Illuminate\Support\Facades\Response::class,
+ 'Route' => Illuminate\Support\Facades\Route::class,
+ 'Schema' => Illuminate\Support\Facades\Schema::class,
+ 'Session' => Illuminate\Support\Facades\Session::class,
+ 'Storage' => Illuminate\Support\Facades\Storage::class,
+ 'URL' => Illuminate\Support\Facades\URL::class,
+ 'Validator' => Illuminate\Support\Facades\Validator::class,
+ 'View' => Illuminate\Support\Facades\View::class,
+
+ /*
+ * App aliases...
+ */
+ 'Broker' => Nasqueron\Notifications\Facades\Broker::class,
+ 'DockerHub' => Nasqueron\Notifications\Facades\DockerHub::class,
+ 'Mailgun' => Nasqueron\Notifications\Facades\Mailgun::class,
+ 'PhabricatorAPI' => Nasqueron\Notifications\Facades\PhabricatorAPI::class,
+ 'ProjectsMap' => Nasqueron\Notifications\Facades\ProjectsMap::class,
+ 'Raven' => Nasqueron\Notifications\Facades\Raven::class,
+ 'Report' => Nasqueron\Notifications\Facades\Report::class,
+ 'Services' => Nasqueron\Notifications\Facades\Services::class,
+
+ ],
];
diff --git a/config/auth.php b/config/auth.php
--- a/config/auth.php
+++ b/config/auth.php
@@ -2,101 +2,101 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Authentication Defaults
- |--------------------------------------------------------------------------
- |
- | This option controls the default authentication "guard" and password
- | reset options for your application. You may change these defaults
- | as required, but they're a perfect start for most applications.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Authentication Defaults
+ |--------------------------------------------------------------------------
+ |
+ | This option controls the default authentication "guard" and password
+ | reset options for your application. You may change these defaults
+ | as required, but they're a perfect start for most applications.
+ |
+ */
- 'defaults' => [
- 'guard' => 'web',
- 'passwords' => 'users',
- ],
+ 'defaults' => [
+ 'guard' => 'web',
+ 'passwords' => 'users',
+ ],
- /*
- |--------------------------------------------------------------------------
- | Authentication Guards
- |--------------------------------------------------------------------------
- |
- | Next, you may define every authentication guard for your application.
- | Of course, a great default configuration has been defined for you
- | here which uses session storage and the Eloquent user provider.
- |
- | All authentication drivers have a user provider. This defines how the
- | users are actually retrieved out of your database or other storage
- | mechanisms used by this application to persist your user's data.
- |
- | Supported: "session", "token"
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Authentication Guards
+ |--------------------------------------------------------------------------
+ |
+ | Next, you may define every authentication guard for your application.
+ | Of course, a great default configuration has been defined for you
+ | here which uses session storage and the Eloquent user provider.
+ |
+ | All authentication drivers have a user provider. This defines how the
+ | users are actually retrieved out of your database or other storage
+ | mechanisms used by this application to persist your user's data.
+ |
+ | Supported: "session", "token"
+ |
+ */
- 'guards' => [
- 'web' => [
- 'driver' => 'session',
- 'provider' => 'users',
- ],
+ 'guards' => [
+ 'web' => [
+ 'driver' => 'session',
+ 'provider' => 'users',
+ ],
- 'api' => [
- 'driver' => 'token',
- 'provider' => 'users',
- ],
- ],
+ 'api' => [
+ 'driver' => 'token',
+ 'provider' => 'users',
+ ],
+ ],
- /*
- |--------------------------------------------------------------------------
- | User Providers
- |--------------------------------------------------------------------------
- |
- | All authentication drivers have a user provider. This defines how the
- | users are actually retrieved out of your database or other storage
- | mechanisms used by this application to persist your user's data.
- |
- | If you have multiple user tables or models you may configure multiple
- | sources which represent each model / table. These sources may then
- | be assigned to any extra authentication guards you have defined.
- |
- | Supported: "database", "eloquent"
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | User Providers
+ |--------------------------------------------------------------------------
+ |
+ | All authentication drivers have a user provider. This defines how the
+ | users are actually retrieved out of your database or other storage
+ | mechanisms used by this application to persist your user's data.
+ |
+ | If you have multiple user tables or models you may configure multiple
+ | sources which represent each model / table. These sources may then
+ | be assigned to any extra authentication guards you have defined.
+ |
+ | Supported: "database", "eloquent"
+ |
+ */
- 'providers' => [
- 'users' => [
- 'driver' => 'eloquent',
- 'model' => Nasqueron\Notifications\User::class,
- ]
- ],
+ 'providers' => [
+ 'users' => [
+ 'driver' => 'eloquent',
+ 'model' => Nasqueron\Notifications\User::class,
+ ]
+ ],
- /*
- |--------------------------------------------------------------------------
- | Resetting Passwords
- |--------------------------------------------------------------------------
- |
- | Here you may set the options for resetting passwords including the view
- | that is your password reset e-mail. You may also set the name of the
- | table that maintains all of the reset tokens for your application.
- |
- | You may specify multiple password reset configurations if you have more
- | than one user table or model in the application and you want to have
- | separate password reset settings based on the specific user types.
- |
- | The expire time is the number of minutes that the reset token should be
- | considered valid. This security feature keeps tokens short-lived so
- | they have less time to be guessed. You may change this as needed.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Resetting Passwords
+ |--------------------------------------------------------------------------
+ |
+ | Here you may set the options for resetting passwords including the view
+ | that is your password reset e-mail. You may also set the name of the
+ | table that maintains all of the reset tokens for your application.
+ |
+ | You may specify multiple password reset configurations if you have more
+ | than one user table or model in the application and you want to have
+ | separate password reset settings based on the specific user types.
+ |
+ | The expire time is the number of minutes that the reset token should be
+ | considered valid. This security feature keeps tokens short-lived so
+ | they have less time to be guessed. You may change this as needed.
+ |
+ */
- 'passwords' => [
- 'users' => [
- 'provider' => 'users',
- 'email' => 'auth.emails.password',
- 'table' => 'password_resets',
- 'expire' => 60,
- ],
- ],
+ 'passwords' => [
+ 'users' => [
+ 'provider' => 'users',
+ 'email' => 'auth.emails.password',
+ 'table' => 'password_resets',
+ 'expire' => 60,
+ ],
+ ],
];
diff --git a/config/broadcasting.php b/config/broadcasting.php
--- a/config/broadcasting.php
+++ b/config/broadcasting.php
@@ -2,51 +2,51 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Default Broadcaster
- |--------------------------------------------------------------------------
- |
- | This option controls the default broadcaster that will be used by the
- | framework when an event needs to be broadcast. You may set this to
- | any of the connections defined in the "connections" array below.
- |
- */
-
- 'default' => env('BROADCAST_DRIVER', 'pusher'),
-
- /*
- |--------------------------------------------------------------------------
- | Broadcast Connections
- |--------------------------------------------------------------------------
- |
- | Here you may define all of the broadcast connections that will be used
- | to broadcast events to other systems or over websockets. Samples of
- | each available type of connection are provided inside this array.
- |
- */
-
- 'connections' => [
-
- 'pusher' => [
- 'driver' => 'pusher',
- 'key' => env('PUSHER_KEY'),
- 'secret' => env('PUSHER_SECRET'),
- 'app_id' => env('PUSHER_APP_ID'),
- 'options' => [
- //
- ],
- ],
-
- 'redis' => [
- 'driver' => 'redis',
- 'connection' => 'default',
- ],
-
- 'log' => [
- 'driver' => 'log',
- ],
-
- ],
+ /*
+ |--------------------------------------------------------------------------
+ | Default Broadcaster
+ |--------------------------------------------------------------------------
+ |
+ | This option controls the default broadcaster that will be used by the
+ | framework when an event needs to be broadcast. You may set this to
+ | any of the connections defined in the "connections" array below.
+ |
+ */
+
+ 'default' => env( 'BROADCAST_DRIVER', 'pusher' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Broadcast Connections
+ |--------------------------------------------------------------------------
+ |
+ | Here you may define all of the broadcast connections that will be used
+ | to broadcast events to other systems or over websockets. Samples of
+ | each available type of connection are provided inside this array.
+ |
+ */
+
+ 'connections' => [
+
+ 'pusher' => [
+ 'driver' => 'pusher',
+ 'key' => env( 'PUSHER_KEY' ),
+ 'secret' => env( 'PUSHER_SECRET' ),
+ 'app_id' => env( 'PUSHER_APP_ID' ),
+ 'options' => [
+ //
+ ],
+ ],
+
+ 'redis' => [
+ 'driver' => 'redis',
+ 'connection' => 'default',
+ ],
+
+ 'log' => [
+ 'driver' => 'log',
+ ],
+
+ ],
];
diff --git a/config/broker.php b/config/broker.php
--- a/config/broker.php
+++ b/config/broker.php
@@ -2,66 +2,66 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Default message broker driver
- |--------------------------------------------------------------------------
- |
- | This option controls the default message broker "driver" that will be
- | used to send messages.
- |
- | Supported: "amqp"
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Default message broker driver
+ |--------------------------------------------------------------------------
+ |
+ | This option controls the default message broker "driver" that will be
+ | used to send messages.
+ |
+ | Supported: "amqp"
+ |
+ */
- 'driver' => env('BROKER_DRIVER', 'amqp'),
+ 'driver' => env( 'BROKER_DRIVER', 'amqp' ),
- /*
- |--------------------------------------------------------------------------
- | Message broker connections
- |--------------------------------------------------------------------------
- |
- | Here are each of the message broker connections setup for the application.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Message broker connections
+ |--------------------------------------------------------------------------
+ |
+ | Here are each of the message broker connections setup for the application.
+ |
+ */
- 'connections' => [
+ 'connections' => [
- 'amqp' => [
- 'driver' => 'amqp',
- 'host' => env('BROKER_HOST', 'localhost'),
- 'port' => env('BROKER_PORT', 5672),
- 'username' => env('BROKER_USERNAME', 'guest'),
- 'password' => env('BROKER_PASSWORD', 'guest'),
- 'vhost' => env('BROKER_VHOST', '/'),
- ],
+ 'amqp' => [
+ 'driver' => 'amqp',
+ 'host' => env( 'BROKER_HOST', 'localhost' ),
+ 'port' => env( 'BROKER_PORT', 5672 ),
+ 'username' => env( 'BROKER_USERNAME', 'guest' ),
+ 'password' => env( 'BROKER_PASSWORD', 'guest' ),
+ 'vhost' => env( 'BROKER_VHOST', '/' ),
+ ],
- 'blackhole' => [
- 'driver' => 'blackhole',
- ]
+ 'blackhole' => [
+ 'driver' => 'blackhole',
+ ]
- ],
+ ],
- /*
- |--------------------------------------------------------------------------
- | Message broker targets
- |--------------------------------------------------------------------------
- |
- | For AMQP, there are exchange points. For other brokers, they could be
- | queues if exchanges are not implemented.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Message broker targets
+ |--------------------------------------------------------------------------
+ |
+ | For AMQP, there are exchange points. For other brokers, they could be
+ | queues if exchanges are not implemented.
+ |
+ */
- 'targets' => [
- // A stream of all payloads sent by GitHub, to provide a gateway
- // GitHub Webhooks API => broker. They are sorted by topics under
- // the pattern <gate door>.<group>.<event type>.
- 'github_events' => 'github_events',
+ 'targets' => [
+ // A stream of all payloads sent by GitHub, to provide a gateway
+ // GitHub Webhooks API => broker. They are sorted by topics under
+ // the pattern <gate door>.<group>.<event type>.
+ 'github_events' => 'github_events',
- // A stream of selected events, to display a textual notification.
- // They are sorted by topics under the following pattern:
- // <service>.<project>.<group>.<type>
- 'notifications' => 'notifications',
- ]
+ // A stream of selected events, to display a textual notification.
+ // They are sorted by topics under the following pattern:
+ // <service>.<project>.<group>.<type>
+ 'notifications' => 'notifications',
+ ]
];
diff --git a/config/cache.php b/config/cache.php
--- a/config/cache.php
+++ b/config/cache.php
@@ -2,78 +2,78 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Default Cache Store
- |--------------------------------------------------------------------------
- |
- | This option controls the default cache connection that gets used while
- | using this caching library. This connection is used when another is
- | not explicitly specified when executing a given caching function.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Default Cache Store
+ |--------------------------------------------------------------------------
+ |
+ | This option controls the default cache connection that gets used while
+ | using this caching library. This connection is used when another is
+ | not explicitly specified when executing a given caching function.
+ |
+ */
- 'default' => env('CACHE_DRIVER', 'file'),
+ 'default' => env( 'CACHE_DRIVER', 'file' ),
- /*
- |--------------------------------------------------------------------------
- | Cache Stores
- |--------------------------------------------------------------------------
- |
- | Here you may define all of the cache "stores" for your application as
- | well as their drivers. You may even define multiple stores for the
- | same cache driver to group types of items stored in your caches.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Cache Stores
+ |--------------------------------------------------------------------------
+ |
+ | Here you may define all of the cache "stores" for your application as
+ | well as their drivers. You may even define multiple stores for the
+ | same cache driver to group types of items stored in your caches.
+ |
+ */
- 'stores' => [
+ 'stores' => [
- 'apc' => [
- 'driver' => 'apc',
- ],
+ 'apc' => [
+ 'driver' => 'apc',
+ ],
- 'array' => [
- 'driver' => 'array',
- ],
+ 'array' => [
+ 'driver' => 'array',
+ ],
- 'database' => [
- 'driver' => 'database',
- 'table' => 'cache',
- 'connection' => null,
- ],
+ 'database' => [
+ 'driver' => 'database',
+ 'table' => 'cache',
+ 'connection' => null,
+ ],
- 'file' => [
- 'driver' => 'file',
- 'path' => storage_path('framework/cache'),
- ],
+ 'file' => [
+ 'driver' => 'file',
+ 'path' => storage_path( 'framework/cache' ),
+ ],
- 'memcached' => [
- 'driver' => 'memcached',
- 'servers' => [
- [
- 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100,
- ],
- ],
- ],
+ 'memcached' => [
+ 'driver' => 'memcached',
+ 'servers' => [
+ [
+ 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100,
+ ],
+ ],
+ ],
- 'redis' => [
- 'driver' => 'redis',
- 'connection' => 'default',
- ],
+ 'redis' => [
+ 'driver' => 'redis',
+ 'connection' => 'default',
+ ],
- ],
+ ],
- /*
- |--------------------------------------------------------------------------
- | Cache Key Prefix
- |--------------------------------------------------------------------------
- |
- | When utilizing a RAM based store such as APC or Memcached, there might
- | be other applications utilizing the same cache. So, we'll specify a
- | value to get prefixed to all our keys so we can avoid collisions.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Cache Key Prefix
+ |--------------------------------------------------------------------------
+ |
+ | When utilizing a RAM based store such as APC or Memcached, there might
+ | be other applications utilizing the same cache. So, we'll specify a
+ | value to get prefixed to all our keys so we can avoid collisions.
+ |
+ */
- 'prefix' => 'notifs',
+ 'prefix' => 'notifs',
];
diff --git a/config/compile.php b/config/compile.php
--- a/config/compile.php
+++ b/config/compile.php
@@ -2,34 +2,34 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Additional Compiled Classes
- |--------------------------------------------------------------------------
- |
- | Here you may specify additional classes to include in the compiled file
- | generated by the `artisan optimize` command. These should be classes
- | that are included on basically every request into the application.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Additional Compiled Classes
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify additional classes to include in the compiled file
+ | generated by the `artisan optimize` command. These should be classes
+ | that are included on basically every request into the application.
+ |
+ */
- 'files' => [
- //
- ],
+ 'files' => [
+ //
+ ],
- /*
- |--------------------------------------------------------------------------
- | Compiled File Providers
- |--------------------------------------------------------------------------
- |
- | Here you may list service providers which define a "compiles" function
- | that returns additional files that should be compiled, providing an
- | easy way to get common files from any packages you are utilizing.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Compiled File Providers
+ |--------------------------------------------------------------------------
+ |
+ | Here you may list service providers which define a "compiles" function
+ | that returns additional files that should be compiled, providing an
+ | easy way to get common files from any packages you are utilizing.
+ |
+ */
- 'providers' => [
- //
- ],
+ 'providers' => [
+ //
+ ],
];
diff --git a/config/database.php b/config/database.php
--- a/config/database.php
+++ b/config/database.php
@@ -2,125 +2,125 @@
return [
- /*
- |--------------------------------------------------------------------------
- | PDO Fetch Style
- |--------------------------------------------------------------------------
- |
- | By default, database results will be returned as instances of the PHP
- | stdClass object; however, you may desire to retrieve records in an
- | array format for simplicity. Here you can tweak the fetch style.
- |
- */
-
- 'fetch' => PDO::FETCH_CLASS,
-
- /*
- |--------------------------------------------------------------------------
- | Default Database Connection Name
- |--------------------------------------------------------------------------
- |
- | Here you may specify which of the database connections below you wish
- | to use as your default connection for all database work. Of course
- | you may use many connections at once using the Database library.
- |
- */
-
- 'default' => env('DB_CONNECTION', 'mysql'),
-
- /*
- |--------------------------------------------------------------------------
- | Database Connections
- |--------------------------------------------------------------------------
- |
- | Here are each of the database connections setup for your application.
- | Of course, examples of configuring each database platform that is
- | supported by Laravel is shown below to make development simple.
- |
- |
- | All database work in Laravel is done through the PHP PDO facilities
- | so make sure you have the driver for your particular database of
- | choice installed on your machine before you begin development.
- |
- */
-
- 'connections' => [
-
- 'sqlite' => [
- 'driver' => 'sqlite',
- 'database' => database_path('database.sqlite'),
- 'prefix' => '',
- ],
-
- 'mysql' => [
- 'driver' => 'mysql',
- 'host' => env('DB_HOST', 'localhost'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
- 'charset' => 'utf8',
- 'collation' => 'utf8_unicode_ci',
- 'prefix' => '',
- 'strict' => false,
- ],
-
- 'pgsql' => [
- 'driver' => 'pgsql',
- 'host' => env('DB_HOST', 'localhost'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
- 'charset' => 'utf8',
- 'prefix' => '',
- 'schema' => 'public',
- ],
-
- 'sqlsrv' => [
- 'driver' => 'sqlsrv',
- 'host' => env('DB_HOST', 'localhost'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
- 'charset' => 'utf8',
- 'prefix' => '',
- ],
-
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Migration Repository Table
- |--------------------------------------------------------------------------
- |
- | This table keeps track of all the migrations that have already run for
- | your application. Using this information, we can determine which of
- | the migrations on disk haven't actually been run in the database.
- |
- */
-
- 'migrations' => 'migrations',
-
- /*
- |--------------------------------------------------------------------------
- | Redis Databases
- |--------------------------------------------------------------------------
- |
- | Redis is an open source, fast, and advanced key-value store that also
- | provides a richer set of commands than a typical key-value systems
- | such as APC or Memcached. Laravel makes it easy to dig right in.
- |
- */
-
- 'redis' => [
-
- 'cluster' => false,
-
- 'default' => [
- 'host' => '127.0.0.1',
- 'port' => 6379,
- 'database' => 0,
- ],
-
- ],
+ /*
+ |--------------------------------------------------------------------------
+ | PDO Fetch Style
+ |--------------------------------------------------------------------------
+ |
+ | By default, database results will be returned as instances of the PHP
+ | stdClass object; however, you may desire to retrieve records in an
+ | array format for simplicity. Here you can tweak the fetch style.
+ |
+ */
+
+ 'fetch' => PDO::FETCH_CLASS,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Default Database Connection Name
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify which of the database connections below you wish
+ | to use as your default connection for all database work. Of course
+ | you may use many connections at once using the Database library.
+ |
+ */
+
+ 'default' => env( 'DB_CONNECTION', 'mysql' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Database Connections
+ |--------------------------------------------------------------------------
+ |
+ | Here are each of the database connections setup for your application.
+ | Of course, examples of configuring each database platform that is
+ | supported by Laravel is shown below to make development simple.
+ |
+ |
+ | All database work in Laravel is done through the PHP PDO facilities
+ | so make sure you have the driver for your particular database of
+ | choice installed on your machine before you begin development.
+ |
+ */
+
+ 'connections' => [
+
+ 'sqlite' => [
+ 'driver' => 'sqlite',
+ 'database' => database_path( 'database.sqlite' ),
+ 'prefix' => '',
+ ],
+
+ 'mysql' => [
+ 'driver' => 'mysql',
+ 'host' => env( 'DB_HOST', 'localhost' ),
+ 'database' => env( 'DB_DATABASE', 'forge' ),
+ 'username' => env( 'DB_USERNAME', 'forge' ),
+ 'password' => env( 'DB_PASSWORD', '' ),
+ 'charset' => 'utf8',
+ 'collation' => 'utf8_unicode_ci',
+ 'prefix' => '',
+ 'strict' => false,
+ ],
+
+ 'pgsql' => [
+ 'driver' => 'pgsql',
+ 'host' => env( 'DB_HOST', 'localhost' ),
+ 'database' => env( 'DB_DATABASE', 'forge' ),
+ 'username' => env( 'DB_USERNAME', 'forge' ),
+ 'password' => env( 'DB_PASSWORD', '' ),
+ 'charset' => 'utf8',
+ 'prefix' => '',
+ 'schema' => 'public',
+ ],
+
+ 'sqlsrv' => [
+ 'driver' => 'sqlsrv',
+ 'host' => env( 'DB_HOST', 'localhost' ),
+ 'database' => env( 'DB_DATABASE', 'forge' ),
+ 'username' => env( 'DB_USERNAME', 'forge' ),
+ 'password' => env( 'DB_PASSWORD', '' ),
+ 'charset' => 'utf8',
+ 'prefix' => '',
+ ],
+
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Migration Repository Table
+ |--------------------------------------------------------------------------
+ |
+ | This table keeps track of all the migrations that have already run for
+ | your application. Using this information, we can determine which of
+ | the migrations on disk haven't actually been run in the database.
+ |
+ */
+
+ 'migrations' => 'migrations',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Redis Databases
+ |--------------------------------------------------------------------------
+ |
+ | Redis is an open source, fast, and advanced key-value store that also
+ | provides a richer set of commands than a typical key-value systems
+ | such as APC or Memcached. Laravel makes it easy to dig right in.
+ |
+ */
+
+ 'redis' => [
+
+ 'cluster' => false,
+
+ 'default' => [
+ 'host' => '127.0.0.1',
+ 'port' => 6379,
+ 'database' => 0,
+ ],
+
+ ],
];
diff --git a/config/filesystems.php b/config/filesystems.php
--- a/config/filesystems.php
+++ b/config/filesystems.php
@@ -2,86 +2,86 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Default Filesystem Disk
- |--------------------------------------------------------------------------
- |
- | Here you may specify the default filesystem disk that should be used
- | by the framework. A "local" driver, as well as a variety of cloud
- | based drivers are available for your choosing. Just store away!
- |
- | Supported: "local", "ftp", "s3", "rackspace"
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Default Filesystem Disk
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify the default filesystem disk that should be used
+ | by the framework. A "local" driver, as well as a variety of cloud
+ | based drivers are available for your choosing. Just store away!
+ |
+ | Supported: "local", "ftp", "s3", "rackspace"
+ |
+ */
- 'default' => 'local',
+ 'default' => 'local',
- /*
- |--------------------------------------------------------------------------
- | Default Cloud Filesystem Disk
- |--------------------------------------------------------------------------
- |
- | Many applications store files both locally and in the cloud. For this
- | reason, you may specify a default "cloud" driver here. This driver
- | will be bound as the Cloud disk implementation in the container.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Default Cloud Filesystem Disk
+ |--------------------------------------------------------------------------
+ |
+ | Many applications store files both locally and in the cloud. For this
+ | reason, you may specify a default "cloud" driver here. This driver
+ | will be bound as the Cloud disk implementation in the container.
+ |
+ */
- 'cloud' => 's3',
+ 'cloud' => 's3',
- /*
- |--------------------------------------------------------------------------
- | Filesystem Disks
- |--------------------------------------------------------------------------
- |
- | Here you may configure as many filesystem "disks" as you wish, and you
- | may even configure multiple disks of the same driver. Defaults have
- | been setup for each driver as an example of the required options.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Filesystem Disks
+ |--------------------------------------------------------------------------
+ |
+ | Here you may configure as many filesystem "disks" as you wish, and you
+ | may even configure multiple disks of the same driver. Defaults have
+ | been setup for each driver as an example of the required options.
+ |
+ */
- 'disks' => [
+ 'disks' => [
- 'local' => [
- 'driver' => 'local',
- 'root' => (env('APP_ENV') == 'testing') ?
- base_path('tests/data') :
- storage_path('app'),
- ],
+ 'local' => [
+ 'driver' => 'local',
+ 'root' => ( env( 'APP_ENV' ) == 'testing' ) ?
+ base_path( 'tests/data' ) :
+ storage_path( 'app' ),
+ ],
- 'ftp' => [
- 'driver' => 'ftp',
- 'host' => 'ftp.example.com',
- 'username' => 'your-username',
- 'password' => 'your-password',
+ 'ftp' => [
+ 'driver' => 'ftp',
+ 'host' => 'ftp.example.com',
+ 'username' => 'your-username',
+ 'password' => 'your-password',
- // Optional FTP Settings...
- // 'port' => 21,
- // 'root' => '',
- // 'passive' => true,
- // 'ssl' => true,
- // 'timeout' => 30,
- ],
+ // Optional FTP Settings...
+ // 'port' => 21,
+ // 'root' => '',
+ // 'passive' => true,
+ // 'ssl' => true,
+ // 'timeout' => 30,
+ ],
- 's3' => [
- 'driver' => 's3',
- 'key' => 'your-key',
- 'secret' => 'your-secret',
- 'region' => 'your-region',
- 'bucket' => 'your-bucket',
- ],
+ 's3' => [
+ 'driver' => 's3',
+ 'key' => 'your-key',
+ 'secret' => 'your-secret',
+ 'region' => 'your-region',
+ 'bucket' => 'your-bucket',
+ ],
- 'rackspace' => [
- 'driver' => 'rackspace',
- 'username' => 'your-username',
- 'key' => 'your-key',
- 'container' => 'your-container',
- 'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
- 'region' => 'IAD',
- 'url_type' => 'publicURL',
- ],
+ 'rackspace' => [
+ 'driver' => 'rackspace',
+ 'username' => 'your-username',
+ 'key' => 'your-key',
+ 'container' => 'your-container',
+ 'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
+ 'region' => 'IAD',
+ 'url_type' => 'publicURL',
+ ],
- ],
+ ],
];
diff --git a/config/gate.php b/config/gate.php
--- a/config/gate.php
+++ b/config/gate.php
@@ -2,25 +2,25 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Gate controllers
- |--------------------------------------------------------------------------
- |
- | Notifications center accept payload from several services and calls
- | matching gate controllers to process messages.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Gate controllers
+ |--------------------------------------------------------------------------
+ |
+ | Notifications center accept payload from several services and calls
+ | matching gate controllers to process messages.
+ |
+ */
- 'controllers' => [
- // Native notifications
- 'Notification',
+ 'controllers' => [
+ // Native notifications
+ 'Notification',
- // External services
- 'DockerHub',
- 'GitHub',
- 'Jenkins',
- 'Phabricator',
- ],
+ // External services
+ 'DockerHub',
+ 'GitHub',
+ 'Jenkins',
+ 'Phabricator',
+ ],
];
diff --git a/config/mail.php b/config/mail.php
--- a/config/mail.php
+++ b/config/mail.php
@@ -2,123 +2,123 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Mail Driver
- |--------------------------------------------------------------------------
- |
- | Laravel supports both SMTP and PHP's "mail" function as drivers for the
- | sending of e-mail. You may specify which one you're using throughout
- | your application here. By default, Laravel is setup for SMTP mail.
- |
- | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "ses", "log"
- |
- */
-
- 'driver' => env('MAIL_DRIVER', 'smtp'),
-
- /*
- |--------------------------------------------------------------------------
- | SMTP Host Address
- |--------------------------------------------------------------------------
- |
- | Here you may provide the host address of the SMTP server used by your
- | applications. A default option is provided that is compatible with
- | the Mailgun mail service which will provide reliable deliveries.
- |
- */
-
- 'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
-
- /*
- |--------------------------------------------------------------------------
- | SMTP Host Port
- |--------------------------------------------------------------------------
- |
- | This is the SMTP port used by your application to deliver e-mails to
- | users of the application. Like the host we have set this value to
- | stay compatible with the Mailgun e-mail application by default.
- |
- */
-
- 'port' => env('MAIL_PORT', 587),
-
- /*
- |--------------------------------------------------------------------------
- | Global "From" Address
- |--------------------------------------------------------------------------
- |
- | You may wish for all e-mails sent by your application to be sent from
- | the same address. Here, you may specify a name and address that is
- | used globally for all e-mails that are sent by your application.
- |
- */
-
- 'from' => ['address' => null, 'name' => null],
-
- /*
- |--------------------------------------------------------------------------
- | E-Mail Encryption Protocol
- |--------------------------------------------------------------------------
- |
- | Here you may specify the encryption protocol that should be used when
- | the application send e-mail messages. A sensible default using the
- | transport layer security protocol should provide great security.
- |
- */
-
- 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
-
- /*
- |--------------------------------------------------------------------------
- | SMTP Server Username
- |--------------------------------------------------------------------------
- |
- | If your SMTP server requires a username for authentication, you should
- | set it here. This will get used to authenticate with your server on
- | connection. You may also set the "password" value below this one.
- |
- */
-
- 'username' => env('MAIL_USERNAME'),
-
- /*
- |--------------------------------------------------------------------------
- | SMTP Server Password
- |--------------------------------------------------------------------------
- |
- | Here you may set the password required by your SMTP server to send out
- | messages from your application. This will be given to the server on
- | connection so that the application will be able to send messages.
- |
- */
-
- 'password' => env('MAIL_PASSWORD'),
-
- /*
- |--------------------------------------------------------------------------
- | Sendmail System Path
- |--------------------------------------------------------------------------
- |
- | When using the "sendmail" driver to send e-mails, we will need to know
- | the path to where Sendmail lives on this server. A default path has
- | been provided here, which will work well on most of your systems.
- |
- */
-
- 'sendmail' => '/usr/sbin/sendmail -bs',
-
- /*
- |--------------------------------------------------------------------------
- | Mail "Pretend"
- |--------------------------------------------------------------------------
- |
- | When this option is enabled, e-mail will not actually be sent over the
- | web and will instead be written to your application's logs files so
- | you may inspect the message. This is great for local development.
- |
- */
-
- 'pretend' => env('MAIL_PRETEND', false),
+ /*
+ |--------------------------------------------------------------------------
+ | Mail Driver
+ |--------------------------------------------------------------------------
+ |
+ | Laravel supports both SMTP and PHP's "mail" function as drivers for the
+ | sending of e-mail. You may specify which one you're using throughout
+ | your application here. By default, Laravel is setup for SMTP mail.
+ |
+ | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "ses", "log"
+ |
+ */
+
+ 'driver' => env( 'MAIL_DRIVER', 'smtp' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | SMTP Host Address
+ |--------------------------------------------------------------------------
+ |
+ | Here you may provide the host address of the SMTP server used by your
+ | applications. A default option is provided that is compatible with
+ | the Mailgun mail service which will provide reliable deliveries.
+ |
+ */
+
+ 'host' => env( 'MAIL_HOST', 'smtp.mailgun.org' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | SMTP Host Port
+ |--------------------------------------------------------------------------
+ |
+ | This is the SMTP port used by your application to deliver e-mails to
+ | users of the application. Like the host we have set this value to
+ | stay compatible with the Mailgun e-mail application by default.
+ |
+ */
+
+ 'port' => env( 'MAIL_PORT', 587 ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Global "From" Address
+ |--------------------------------------------------------------------------
+ |
+ | You may wish for all e-mails sent by your application to be sent from
+ | the same address. Here, you may specify a name and address that is
+ | used globally for all e-mails that are sent by your application.
+ |
+ */
+
+ 'from' => [ 'address' => null, 'name' => null ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | E-Mail Encryption Protocol
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify the encryption protocol that should be used when
+ | the application send e-mail messages. A sensible default using the
+ | transport layer security protocol should provide great security.
+ |
+ */
+
+ 'encryption' => env( 'MAIL_ENCRYPTION', 'tls' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | SMTP Server Username
+ |--------------------------------------------------------------------------
+ |
+ | If your SMTP server requires a username for authentication, you should
+ | set it here. This will get used to authenticate with your server on
+ | connection. You may also set the "password" value below this one.
+ |
+ */
+
+ 'username' => env( 'MAIL_USERNAME' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | SMTP Server Password
+ |--------------------------------------------------------------------------
+ |
+ | Here you may set the password required by your SMTP server to send out
+ | messages from your application. This will be given to the server on
+ | connection so that the application will be able to send messages.
+ |
+ */
+
+ 'password' => env( 'MAIL_PASSWORD' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Sendmail System Path
+ |--------------------------------------------------------------------------
+ |
+ | When using the "sendmail" driver to send e-mails, we will need to know
+ | the path to where Sendmail lives on this server. A default path has
+ | been provided here, which will work well on most of your systems.
+ |
+ */
+
+ 'sendmail' => '/usr/sbin/sendmail -bs',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Mail "Pretend"
+ |--------------------------------------------------------------------------
+ |
+ | When this option is enabled, e-mail will not actually be sent over the
+ | web and will instead be written to your application's logs files so
+ | you may inspect the message. This is great for local development.
+ |
+ */
+
+ 'pretend' => env( 'MAIL_PRETEND', false ),
];
diff --git a/config/queue.php b/config/queue.php
--- a/config/queue.php
+++ b/config/queue.php
@@ -2,93 +2,93 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Default Queue Driver
- |--------------------------------------------------------------------------
- |
- | The Laravel queue API supports a variety of back-ends via an unified
- | API, giving you convenient access to each back-end using the same
- | syntax for each one. Here you may set the default queue driver.
- |
- | Supported: "null", "sync", "database", "beanstalkd",
- | "sqs", "iron", "redis"
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Default Queue Driver
+ |--------------------------------------------------------------------------
+ |
+ | The Laravel queue API supports a variety of back-ends via an unified
+ | API, giving you convenient access to each back-end using the same
+ | syntax for each one. Here you may set the default queue driver.
+ |
+ | Supported: "null", "sync", "database", "beanstalkd",
+ | "sqs", "iron", "redis"
+ |
+ */
- 'default' => env('QUEUE_DRIVER', 'sync'),
+ 'default' => env( 'QUEUE_DRIVER', 'sync' ),
- /*
- |--------------------------------------------------------------------------
- | Queue Connections
- |--------------------------------------------------------------------------
- |
- | Here you may configure the connection information for each server that
- | is used by your application. A default configuration has been added
- | for each back-end shipped with Laravel. You are free to add more.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Queue Connections
+ |--------------------------------------------------------------------------
+ |
+ | Here you may configure the connection information for each server that
+ | is used by your application. A default configuration has been added
+ | for each back-end shipped with Laravel. You are free to add more.
+ |
+ */
- 'connections' => [
+ 'connections' => [
- 'sync' => [
- 'driver' => 'sync',
- ],
+ 'sync' => [
+ 'driver' => 'sync',
+ ],
- 'database' => [
- 'driver' => 'database',
- 'table' => 'jobs',
- 'queue' => 'default',
- 'expire' => 60,
- ],
+ 'database' => [
+ 'driver' => 'database',
+ 'table' => 'jobs',
+ 'queue' => 'default',
+ 'expire' => 60,
+ ],
- 'beanstalkd' => [
- 'driver' => 'beanstalkd',
- 'host' => 'localhost',
- 'queue' => 'default',
- 'ttr' => 60,
- ],
+ 'beanstalkd' => [
+ 'driver' => 'beanstalkd',
+ 'host' => 'localhost',
+ 'queue' => 'default',
+ 'ttr' => 60,
+ ],
- 'sqs' => [
- 'driver' => 'sqs',
- 'key' => 'your-public-key',
- 'secret' => 'your-secret-key',
- 'queue' => 'your-queue-url',
- 'region' => 'us-east-1',
- ],
+ 'sqs' => [
+ 'driver' => 'sqs',
+ 'key' => 'your-public-key',
+ 'secret' => 'your-secret-key',
+ 'queue' => 'your-queue-url',
+ 'region' => 'us-east-1',
+ ],
- 'iron' => [
- 'driver' => 'iron',
- 'host' => 'mq-aws-us-east-1.iron.io',
- 'token' => 'your-token',
- 'project' => 'your-project-id',
- 'queue' => 'your-queue-name',
- 'encrypt' => true,
- ],
+ 'iron' => [
+ 'driver' => 'iron',
+ 'host' => 'mq-aws-us-east-1.iron.io',
+ 'token' => 'your-token',
+ 'project' => 'your-project-id',
+ 'queue' => 'your-queue-name',
+ 'encrypt' => true,
+ ],
- 'redis' => [
- 'driver' => 'redis',
- 'connection' => 'default',
- 'queue' => 'default',
- 'expire' => 60,
- ],
+ 'redis' => [
+ 'driver' => 'redis',
+ 'connection' => 'default',
+ 'queue' => 'default',
+ 'expire' => 60,
+ ],
- ],
+ ],
- /*
- |--------------------------------------------------------------------------
- | Failed Queue Jobs
- |--------------------------------------------------------------------------
- |
- | These options configure the behavior of failed queue job logging so you
- | can control which database and table are used to store the jobs that
- | have failed. You may change them to any database / table you wish.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Failed Queue Jobs
+ |--------------------------------------------------------------------------
+ |
+ | These options configure the behavior of failed queue job logging so you
+ | can control which database and table are used to store the jobs that
+ | have failed. You may change them to any database / table you wish.
+ |
+ */
- 'failed' => [
- 'database' => env('DB_CONNECTION', 'mysql'),
- 'table' => 'failed_jobs',
- ],
+ 'failed' => [
+ 'database' => env( 'DB_CONNECTION', 'mysql' ),
+ 'table' => 'failed_jobs',
+ ],
];
diff --git a/config/services.php b/config/services.php
--- a/config/services.php
+++ b/config/services.php
@@ -2,67 +2,67 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Third Party Services
- |--------------------------------------------------------------------------
- |
- | This file is for storing the credentials for third party services such
- | as Stripe, Mailgun, Mandrill, and others. This file provides a sane
- | default location for this type of information, allowing packages
- | to have a conventional place to find your various credentials.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Third Party Services
+ |--------------------------------------------------------------------------
+ |
+ | This file is for storing the credentials for third party services such
+ | as Stripe, Mailgun, Mandrill, and others. This file provides a sane
+ | default location for this type of information, allowing packages
+ | to have a conventional place to find your various credentials.
+ |
+ */
- 'mailgun' => [
- 'domain' => env('MAILGUN_DOMAIN'),
- 'secret' => env('MAILGUN_SECRET'),
- ],
+ 'mailgun' => [
+ 'domain' => env( 'MAILGUN_DOMAIN' ),
+ 'secret' => env( 'MAILGUN_SECRET' ),
+ ],
- 'mandrill' => [
- 'secret' => env('MANDRILL_SECRET'),
- ],
+ 'mandrill' => [
+ 'secret' => env( 'MANDRILL_SECRET' ),
+ ],
- 'ses' => [
- 'key' => env('SES_KEY'),
- 'secret' => env('SES_SECRET'),
- 'region' => 'us-east-1',
- ],
+ 'ses' => [
+ 'key' => env( 'SES_KEY' ),
+ 'secret' => env( 'SES_SECRET' ),
+ 'region' => 'us-east-1',
+ ],
- 'stripe' => [
- 'model' => Nasqueron\Notifications\User::class,
- 'key' => env('STRIPE_KEY'),
- 'secret' => env('STRIPE_SECRET'),
- ],
+ 'stripe' => [
+ 'model' => Nasqueron\Notifications\User::class,
+ 'key' => env( 'STRIPE_KEY' ),
+ 'secret' => env( 'STRIPE_SECRET' ),
+ ],
- 'sentry' => [
- 'dsn' => env('SENTRY_DSN'),
- ],
+ 'sentry' => [
+ 'dsn' => env( 'SENTRY_DSN' ),
+ ],
- 'dockerhub' => [
- 'tokens' => env('DOCKERHUB_TOKENS', 'DockerHubTokens.json')
- ],
+ 'dockerhub' => [
+ 'tokens' => env( 'DOCKERHUB_TOKENS', 'DockerHubTokens.json' )
+ ],
- 'github' => [
- 'analyzer' => [
- 'configDir' => env('GITHUB_ANALYZER_CONFIG_DIR', 'GitHubPayloadAnalyzer')
- ]
- ],
+ 'github' => [
+ 'analyzer' => [
+ 'configDir' => env( 'GITHUB_ANALYZER_CONFIG_DIR', 'GitHubPayloadAnalyzer' )
+ ]
+ ],
- 'jenkins' => [
- 'analyzer' => [
- 'configDir' => env('JENKINS_ANALYZER_CONFIG_DIR', 'JenkinsPayloadAnalyzer')
- ]
- ],
+ 'jenkins' => [
+ 'analyzer' => [
+ 'configDir' => env( 'JENKINS_ANALYZER_CONFIG_DIR', 'JenkinsPayloadAnalyzer' )
+ ]
+ ],
- 'phabricator' => [
- 'analyzer' => [
- 'configDir' => env('PHABRICATOR_ANALYZER_CONFIG_DIR', 'PhabricatorPayloadAnalyzer')
- ]
- ],
+ 'phabricator' => [
+ 'analyzer' => [
+ 'configDir' => env( 'PHABRICATOR_ANALYZER_CONFIG_DIR', 'PhabricatorPayloadAnalyzer' )
+ ]
+ ],
- 'gate' => [
- 'credentials' => env('CREDENTIALS', 'credentials.json'),
- ]
+ 'gate' => [
+ 'credentials' => env( 'CREDENTIALS', 'credentials.json' ),
+ ]
];
diff --git a/config/session.php b/config/session.php
--- a/config/session.php
+++ b/config/session.php
@@ -2,152 +2,152 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Default Session Driver
- |--------------------------------------------------------------------------
- |
- | This option controls the default session "driver" that will be used on
- | requests. By default, we will use the lightweight native driver but
- | you may specify any of the other wonderful drivers provided here.
- |
- | Supported: "file", "cookie", "database", "apc",
- | "memcached", "redis", "array"
- |
- */
-
- 'driver' => env('SESSION_DRIVER', 'file'),
-
- /*
- |--------------------------------------------------------------------------
- | Session Lifetime
- |--------------------------------------------------------------------------
- |
- | Here you may specify the number of minutes that you wish the session
- | to be allowed to remain idle before it expires. If you want them
- | to immediately expire on the browser closing, set that option.
- |
- */
-
- 'lifetime' => 120,
-
- 'expire_on_close' => false,
-
- /*
- |--------------------------------------------------------------------------
- | Session Encryption
- |--------------------------------------------------------------------------
- |
- | This option allows you to easily specify that all of your session data
- | should be encrypted before it is stored. All encryption will be run
- | automatically by Laravel and you can use the Session like normal.
- |
- */
-
- 'encrypt' => false,
-
- /*
- |--------------------------------------------------------------------------
- | Session File Location
- |--------------------------------------------------------------------------
- |
- | When using the native session driver, we need a location where session
- | files may be stored. A default has been set for you but a different
- | location may be specified. This is only needed for file sessions.
- |
- */
-
- 'files' => storage_path('framework/sessions'),
-
- /*
- |--------------------------------------------------------------------------
- | Session Database Connection
- |--------------------------------------------------------------------------
- |
- | When using the "database" or "redis" session drivers, you may specify a
- | connection that should be used to manage these sessions. This should
- | correspond to a connection in your database configuration options.
- |
- */
-
- 'connection' => null,
-
- /*
- |--------------------------------------------------------------------------
- | Session Database Table
- |--------------------------------------------------------------------------
- |
- | When using the "database" session driver, you may specify the table we
- | should use to manage the sessions. Of course, a sensible default is
- | provided for you; however, you are free to change this as needed.
- |
- */
-
- 'table' => 'sessions',
-
- /*
- |--------------------------------------------------------------------------
- | Session Sweeping Lottery
- |--------------------------------------------------------------------------
- |
- | Some session drivers must manually sweep their storage location to get
- | rid of old sessions from storage. Here are the chances that it will
- | happen on a given request. By default, the odds are 2 out of 100.
- |
- */
-
- 'lottery' => [2, 100],
-
- /*
- |--------------------------------------------------------------------------
- | Session Cookie Name
- |--------------------------------------------------------------------------
- |
- | Here you may change the name of the cookie used to identify a session
- | instance by ID. The name specified here will get used every time a
- | new session cookie is created by the framework for every driver.
- |
- */
-
- 'cookie' => 'notifs_session',
-
- /*
- |--------------------------------------------------------------------------
- | Session Cookie Path
- |--------------------------------------------------------------------------
- |
- | The session cookie path determines the path for which the cookie will
- | be regarded as available. Typically, this will be the root path of
- | your application but you are free to change this when necessary.
- |
- */
-
- 'path' => '/',
-
- /*
- |--------------------------------------------------------------------------
- | Session Cookie Domain
- |--------------------------------------------------------------------------
- |
- | Here you may change the domain of the cookie used to identify a session
- | in your application. This will determine which domains the cookie is
- | available to in your application. A sensible default has been set.
- |
- */
-
- 'domain' => null,
-
- /*
- |--------------------------------------------------------------------------
- | HTTPS Only Cookies
- |--------------------------------------------------------------------------
- |
- | By setting this option to true, session cookies will only be sent back
- | to the server if the browser has a HTTPS connection. This will keep
- | the cookie from being sent to you if it can not be done securely.
- |
- */
-
- 'secure' => false,
+ /*
+ |--------------------------------------------------------------------------
+ | Default Session Driver
+ |--------------------------------------------------------------------------
+ |
+ | This option controls the default session "driver" that will be used on
+ | requests. By default, we will use the lightweight native driver but
+ | you may specify any of the other wonderful drivers provided here.
+ |
+ | Supported: "file", "cookie", "database", "apc",
+ | "memcached", "redis", "array"
+ |
+ */
+
+ 'driver' => env( 'SESSION_DRIVER', 'file' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Lifetime
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify the number of minutes that you wish the session
+ | to be allowed to remain idle before it expires. If you want them
+ | to immediately expire on the browser closing, set that option.
+ |
+ */
+
+ 'lifetime' => 120,
+
+ 'expire_on_close' => false,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Encryption
+ |--------------------------------------------------------------------------
+ |
+ | This option allows you to easily specify that all of your session data
+ | should be encrypted before it is stored. All encryption will be run
+ | automatically by Laravel and you can use the Session like normal.
+ |
+ */
+
+ 'encrypt' => false,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session File Location
+ |--------------------------------------------------------------------------
+ |
+ | When using the native session driver, we need a location where session
+ | files may be stored. A default has been set for you but a different
+ | location may be specified. This is only needed for file sessions.
+ |
+ */
+
+ 'files' => storage_path( 'framework/sessions' ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Database Connection
+ |--------------------------------------------------------------------------
+ |
+ | When using the "database" or "redis" session drivers, you may specify a
+ | connection that should be used to manage these sessions. This should
+ | correspond to a connection in your database configuration options.
+ |
+ */
+
+ 'connection' => null,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Database Table
+ |--------------------------------------------------------------------------
+ |
+ | When using the "database" session driver, you may specify the table we
+ | should use to manage the sessions. Of course, a sensible default is
+ | provided for you; however, you are free to change this as needed.
+ |
+ */
+
+ 'table' => 'sessions',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Sweeping Lottery
+ |--------------------------------------------------------------------------
+ |
+ | Some session drivers must manually sweep their storage location to get
+ | rid of old sessions from storage. Here are the chances that it will
+ | happen on a given request. By default, the odds are 2 out of 100.
+ |
+ */
+
+ 'lottery' => [ 2, 100 ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Cookie Name
+ |--------------------------------------------------------------------------
+ |
+ | Here you may change the name of the cookie used to identify a session
+ | instance by ID. The name specified here will get used every time a
+ | new session cookie is created by the framework for every driver.
+ |
+ */
+
+ 'cookie' => 'notifs_session',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Cookie Path
+ |--------------------------------------------------------------------------
+ |
+ | The session cookie path determines the path for which the cookie will
+ | be regarded as available. Typically, this will be the root path of
+ | your application but you are free to change this when necessary.
+ |
+ */
+
+ 'path' => '/',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Cookie Domain
+ |--------------------------------------------------------------------------
+ |
+ | Here you may change the domain of the cookie used to identify a session
+ | in your application. This will determine which domains the cookie is
+ | available to in your application. A sensible default has been set.
+ |
+ */
+
+ 'domain' => null,
+
+ /*
+ |--------------------------------------------------------------------------
+ | HTTPS Only Cookies
+ |--------------------------------------------------------------------------
+ |
+ | By setting this option to true, session cookies will only be sent back
+ | to the server if the browser has a HTTPS connection. This will keep
+ | the cookie from being sent to you if it can not be done securely.
+ |
+ */
+
+ 'secure' => false,
];
diff --git a/config/view.php b/config/view.php
--- a/config/view.php
+++ b/config/view.php
@@ -2,32 +2,32 @@
return [
- /*
- |--------------------------------------------------------------------------
- | View Storage Paths
- |--------------------------------------------------------------------------
- |
- | Most templating systems load templates from disk. Here you may specify
- | an array of paths that should be checked for your views. Of course
- | the usual Laravel view path has already been registered for you.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | View Storage Paths
+ |--------------------------------------------------------------------------
+ |
+ | Most templating systems load templates from disk. Here you may specify
+ | an array of paths that should be checked for your views. Of course
+ | the usual Laravel view path has already been registered for you.
+ |
+ */
- 'paths' => [
- realpath(base_path('resources/views')),
- ],
+ 'paths' => [
+ realpath( base_path( 'resources/views' ) ),
+ ],
- /*
- |--------------------------------------------------------------------------
- | Compiled View Path
- |--------------------------------------------------------------------------
- |
- | This option determines where all the compiled Blade templates will be
- | stored for your application. Typically, this is within the storage
- | directory. However, as usual, you are free to change this value.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Compiled View Path
+ |--------------------------------------------------------------------------
+ |
+ | This option determines where all the compiled Blade templates will be
+ | stored for your application. Typically, this is within the storage
+ | directory. However, as usual, you are free to change this value.
+ |
+ */
- 'compiled' => realpath(storage_path('framework/views')),
+ 'compiled' => realpath( storage_path( 'framework/views' ) ),
];
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+
+<!--
+ =============================================================
+ PHP_CodeSniffer configuration
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ Project: Keruald
+ License: Trivial work, not eligible to copyright
+ Source file: _templates/phpcs.xml.in
+ =============================================================
+ <auto-generated>
+ This file is automatically generated from a template.
+ Changes to this file may cause incorrect behavior
+ and will be lost if the state is redeployed.
+ </auto-generated>
+-->
+
+<ruleset name="Nasqueron">
+ <standard ref="vendor/nasqueron/codestyle/CodeSniffer/ruleset.xml" />
+
+ <!--
+ OmniTools exception
+ Allow dprint_r() and dieprint_r() legacy debug function names
+ -->
+ <rule ref="Generic.NamingConventions.CamelCapsFunctionName.NotCamelCaps">
+ <exclude-pattern>*/_register_to_global_space.php</exclude-pattern>
+ </rule>
+
+ <file>app/*</file>
+
+ <file>config/*</file>
+
+ <file>tests/*</file>
+
+</ruleset>
\ No newline at end of file
diff --git a/public/index.php b/public/index.php
--- a/public/index.php
+++ b/public/index.php
@@ -19,7 +19,7 @@
|
*/
-require __DIR__.'/../bootstrap/autoload.php';
+require __DIR__ . '/../bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
@@ -33,7 +33,7 @@
|
*/
-$app = require_once __DIR__.'/../bootstrap/app.php';
+$app = require_once __DIR__ . '/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
@@ -47,12 +47,12 @@
|
*/
-$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
+$kernel = $app->make( Illuminate\Contracts\Http\Kernel::class );
$response = $kernel->handle(
- $request = Illuminate\Http\Request::capture()
+ $request = Illuminate\Http\Request::capture()
);
$response->send();
-$kernel->terminate($request, $response);
+$kernel->terminate( $request, $response );
diff --git a/resources/lang/en/GitHub.php b/resources/lang/en/GitHub.php
--- a/resources/lang/en/GitHub.php
+++ b/resources/lang/en/GitHub.php
@@ -2,81 +2,81 @@
return [
- /*
- |--------------------------------------------------------------------------
- | GitHub notifications messages
- |--------------------------------------------------------------------------
- |
- | The following language lines are used to localize notifications for events
- | fired by GitHub
- |
- */
-
- 'Separator' => ' — ',
-
- 'Commits' => [
- 'Message' => ':committer committed :title',
- 'Authored' => ' (authored by :author)', // appended to Message
- ],
-
- 'RepoAndBranch' => ':repo (branch :branch)',
-
- 'EventsDescriptions' => [
- 'CommitCommentEvent' => ':author added a comment to :commit: :excerpt',
-
- 'CreateEvent' => 'New :type on :repository: :ref',
- 'CreateEventUnknown' => 'Unknown create reference: :type :ref',
-
- 'DeleteEvent' => 'Removed :type on :repository: :ref',
- 'DeleteEventUnknown' => 'Unknown delete reference: :type :ref',
-
- 'ForkEvent' => ':repo_base has been forked to :repo_fork',
-
- 'IssueCommentEventPerAction' => [
- 'created' => ":author added a comment to issue #:issueNumber — :issueTitle: :excerpt",
- 'edited' => ":author edited a comment to issue #:issueNumber — :issueTitle: :excerpt",
- 'deleted' => ":author deleted a comment to issue #:issueNumber — :issueTitle",
- ],
- 'IssueCommentEventUnknown' => 'Unknown issue comment action: :action',
-
- 'PingEvent' => '« :zen » — GitHub Webhooks ping zen aphorism.',
-
- 'PullRequestEventPerAction' => [
- 'assigned' => ':author has assigned the pull request #:number — :title to :assignee',
- 'unassigned' => ':author has edited the assignees from the pull request #:number — :title',
- 'labeled' => ':author has labeled the pull request #:number — :title',
- 'unlabeled' => ':author has removed a label from the pull request #:number — :title',
- 'opened' => ':author has opened a pull request: #:number — :title',
- 'edited' => ':author has edited the pull request #:number — :title',
- 'closed' => ':author has closed the pull request #:number — :title',
- 'reopened' => ':author has reopened the pull request #:number — :title',
- ],
- 'PullRequestEventUnknown' => 'Unknown pull request action: :action',
-
- 'PushEvent' => [
- '0' => ':user forcely updated :repoAndBranch',
- 'n' => ':user pushed :count commits to :repoAndBranch', // n > 1
- ],
-
- 'RepositoryEventPerAction' => [
- 'created' => 'New repository :repository',
- 'deleted' => "Repository :repository deleted (danger zone)",
- 'publicized' => "Repository :repository is now public",
- 'privatized' => "Repository :repository is now private",
- ],
- 'RepositoryEventFork' => ' (fork)',
- 'RepositoryEventUnknown' => 'Unknown repository action: :action',
-
- 'StatusEvent' => 'Status of :commit: :status',
-
- 'WatchEvent' => ':user starred :repository',
- ],
-
- 'StatusEventState' => [
- 'pending' => 'pending',
- 'success' => 'success',
- 'failure' => 'failure',
- 'error' => 'error',
- ],
+ /*
+ |--------------------------------------------------------------------------
+ | GitHub notifications messages
+ |--------------------------------------------------------------------------
+ |
+ | The following language lines are used to localize notifications for events
+ | fired by GitHub
+ |
+ */
+
+ 'Separator' => ' — ',
+
+ 'Commits' => [
+ 'Message' => ':committer committed :title',
+ 'Authored' => ' (authored by :author)', // appended to Message
+ ],
+
+ 'RepoAndBranch' => ':repo (branch :branch)',
+
+ 'EventsDescriptions' => [
+ 'CommitCommentEvent' => ':author added a comment to :commit: :excerpt',
+
+ 'CreateEvent' => 'New :type on :repository: :ref',
+ 'CreateEventUnknown' => 'Unknown create reference: :type :ref',
+
+ 'DeleteEvent' => 'Removed :type on :repository: :ref',
+ 'DeleteEventUnknown' => 'Unknown delete reference: :type :ref',
+
+ 'ForkEvent' => ':repo_base has been forked to :repo_fork',
+
+ 'IssueCommentEventPerAction' => [
+ 'created' => ":author added a comment to issue #:issueNumber — :issueTitle: :excerpt",
+ 'edited' => ":author edited a comment to issue #:issueNumber — :issueTitle: :excerpt",
+ 'deleted' => ":author deleted a comment to issue #:issueNumber — :issueTitle",
+ ],
+ 'IssueCommentEventUnknown' => 'Unknown issue comment action: :action',
+
+ 'PingEvent' => '« :zen » — GitHub Webhooks ping zen aphorism.',
+
+ 'PullRequestEventPerAction' => [
+ 'assigned' => ':author has assigned the pull request #:number — :title to :assignee',
+ 'unassigned' => ':author has edited the assignees from the pull request #:number — :title',
+ 'labeled' => ':author has labeled the pull request #:number — :title',
+ 'unlabeled' => ':author has removed a label from the pull request #:number — :title',
+ 'opened' => ':author has opened a pull request: #:number — :title',
+ 'edited' => ':author has edited the pull request #:number — :title',
+ 'closed' => ':author has closed the pull request #:number — :title',
+ 'reopened' => ':author has reopened the pull request #:number — :title',
+ ],
+ 'PullRequestEventUnknown' => 'Unknown pull request action: :action',
+
+ 'PushEvent' => [
+ '0' => ':user forcely updated :repoAndBranch',
+ 'n' => ':user pushed :count commits to :repoAndBranch', // n > 1
+ ],
+
+ 'RepositoryEventPerAction' => [
+ 'created' => 'New repository :repository',
+ 'deleted' => "Repository :repository deleted (danger zone)",
+ 'publicized' => "Repository :repository is now public",
+ 'privatized' => "Repository :repository is now private",
+ ],
+ 'RepositoryEventFork' => ' (fork)',
+ 'RepositoryEventUnknown' => 'Unknown repository action: :action',
+
+ 'StatusEvent' => 'Status of :commit: :status',
+
+ 'WatchEvent' => ':user starred :repository',
+ ],
+
+ 'StatusEventState' => [
+ 'pending' => 'pending',
+ 'success' => 'success',
+ 'failure' => 'failure',
+ 'error' => 'error',
+ ],
];
diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.php
--- a/resources/lang/en/auth.php
+++ b/resources/lang/en/auth.php
@@ -2,18 +2,18 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Authentication Language Lines
- |--------------------------------------------------------------------------
- |
- | The following language lines are used during authentication for various
- | messages that we need to display to the user. You are free to modify
- | these language lines according to your application's requirements.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Authentication Language Lines
+ |--------------------------------------------------------------------------
+ |
+ | The following language lines are used during authentication for various
+ | messages that we need to display to the user. You are free to modify
+ | these language lines according to your application's requirements.
+ |
+ */
- 'failed' => 'These credentials do not match our records.',
- 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
+ 'failed' => 'These credentials do not match our records.',
+ 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
];
diff --git a/resources/lang/en/pagination.php b/resources/lang/en/pagination.php
--- a/resources/lang/en/pagination.php
+++ b/resources/lang/en/pagination.php
@@ -2,18 +2,18 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Pagination Language Lines
- |--------------------------------------------------------------------------
- |
- | The following language lines are used by the paginator library to build
- | the simple pagination links. You are free to change them to anything
- | you want to customize your views to better match your application.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Pagination Language Lines
+ |--------------------------------------------------------------------------
+ |
+ | The following language lines are used by the paginator library to build
+ | the simple pagination links. You are free to change them to anything
+ | you want to customize your views to better match your application.
+ |
+ */
- 'previous' => '&laquo; Previous',
- 'next' => 'Next &raquo;',
+ 'previous' => '&laquo; Previous',
+ 'next' => 'Next &raquo;',
];
diff --git a/resources/lang/en/passwords.php b/resources/lang/en/passwords.php
--- a/resources/lang/en/passwords.php
+++ b/resources/lang/en/passwords.php
@@ -2,21 +2,21 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Password Reminder Language Lines
- |--------------------------------------------------------------------------
- |
- | The following language lines are the default lines which match reasons
- | that are given by the password broker for a password update attempt
- | has failed, such as for an invalid token or invalid new password.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Password Reminder Language Lines
+ |--------------------------------------------------------------------------
+ |
+ | The following language lines are the default lines which match reasons
+ | that are given by the password broker for a password update attempt
+ | has failed, such as for an invalid token or invalid new password.
+ |
+ */
- 'password' => 'Passwords must be at least six characters and match the confirmation.',
- 'reset' => 'Your password has been reset!',
- 'sent' => 'We have e-mailed your password reset link!',
- 'token' => 'This password reset token is invalid.',
- 'user' => "We can't find a user with that e-mail address.",
+ 'password' => 'Passwords must be at least six characters and match the confirmation.',
+ 'reset' => 'Your password has been reset!',
+ 'sent' => 'We have e-mailed your password reset link!',
+ 'token' => 'This password reset token is invalid.',
+ 'user' => "We can't find a user with that e-mail address.",
];
diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php
--- a/resources/lang/en/validation.php
+++ b/resources/lang/en/validation.php
@@ -2,109 +2,109 @@
return [
- /*
- |--------------------------------------------------------------------------
- | Validation Language Lines
- |--------------------------------------------------------------------------
- |
- | The following language lines contain the default error messages used by
- | the validator class. Some of these rules have multiple versions such
- | as the size rules. Feel free to tweak each of these messages here.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Validation Language Lines
+ |--------------------------------------------------------------------------
+ |
+ | The following language lines contain the default error messages used by
+ | the validator class. Some of these rules have multiple versions such
+ | as the size rules. Feel free to tweak each of these messages here.
+ |
+ */
- 'accepted' => 'The :attribute must be accepted.',
- 'active_url' => 'The :attribute is not a valid URL.',
- 'after' => 'The :attribute must be a date after :date.',
- 'alpha' => 'The :attribute may only contain letters.',
- 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.',
- 'alpha_num' => 'The :attribute may only contain letters and numbers.',
- 'array' => 'The :attribute must be an array.',
- 'before' => 'The :attribute must be a date before :date.',
- 'between' => [
- 'numeric' => 'The :attribute must be between :min and :max.',
- 'file' => 'The :attribute must be between :min and :max kilobytes.',
- 'string' => 'The :attribute must be between :min and :max characters.',
- 'array' => 'The :attribute must have between :min and :max items.',
- ],
- 'boolean' => 'The :attribute field must be true or false.',
- 'confirmed' => 'The :attribute confirmation does not match.',
- 'date' => 'The :attribute is not a valid date.',
- 'date_format' => 'The :attribute does not match the format :format.',
- 'different' => 'The :attribute and :other must be different.',
- 'digits' => 'The :attribute must be :digits digits.',
- 'digits_between' => 'The :attribute must be between :min and :max digits.',
- 'email' => 'The :attribute must be a valid email address.',
- 'exists' => 'The selected :attribute is invalid.',
- 'filled' => 'The :attribute field is required.',
- 'image' => 'The :attribute must be an image.',
- 'in' => 'The selected :attribute is invalid.',
- 'integer' => 'The :attribute must be an integer.',
- 'ip' => 'The :attribute must be a valid IP address.',
- 'json' => 'The :attribute must be a valid JSON string.',
- 'max' => [
- 'numeric' => 'The :attribute may not be greater than :max.',
- 'file' => 'The :attribute may not be greater than :max kilobytes.',
- 'string' => 'The :attribute may not be greater than :max characters.',
- 'array' => 'The :attribute may not have more than :max items.',
- ],
- 'mimes' => 'The :attribute must be a file of type: :values.',
- 'min' => [
- 'numeric' => 'The :attribute must be at least :min.',
- 'file' => 'The :attribute must be at least :min kilobytes.',
- 'string' => 'The :attribute must be at least :min characters.',
- 'array' => 'The :attribute must have at least :min items.',
- ],
- 'not_in' => 'The selected :attribute is invalid.',
- 'numeric' => 'The :attribute must be a number.',
- 'regex' => 'The :attribute format is invalid.',
- 'required' => 'The :attribute field is required.',
- 'required_if' => 'The :attribute field is required when :other is :value.',
- 'required_unless' => 'The :attribute field is required unless :other is in :values.',
- 'required_with' => 'The :attribute field is required when :values is present.',
- 'required_with_all' => 'The :attribute field is required when :values is present.',
- 'required_without' => 'The :attribute field is required when :values is not present.',
- 'required_without_all' => 'The :attribute field is required when none of :values are present.',
- 'same' => 'The :attribute and :other must match.',
- 'size' => [
- 'numeric' => 'The :attribute must be :size.',
- 'file' => 'The :attribute must be :size kilobytes.',
- 'string' => 'The :attribute must be :size characters.',
- 'array' => 'The :attribute must contain :size items.',
- ],
- 'string' => 'The :attribute must be a string.',
- 'timezone' => 'The :attribute must be a valid zone.',
- 'unique' => 'The :attribute has already been taken.',
- 'url' => 'The :attribute format is invalid.',
+ 'accepted' => 'The :attribute must be accepted.',
+ 'active_url' => 'The :attribute is not a valid URL.',
+ 'after' => 'The :attribute must be a date after :date.',
+ 'alpha' => 'The :attribute may only contain letters.',
+ 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.',
+ 'alpha_num' => 'The :attribute may only contain letters and numbers.',
+ 'array' => 'The :attribute must be an array.',
+ 'before' => 'The :attribute must be a date before :date.',
+ 'between' => [
+ 'numeric' => 'The :attribute must be between :min and :max.',
+ 'file' => 'The :attribute must be between :min and :max kilobytes.',
+ 'string' => 'The :attribute must be between :min and :max characters.',
+ 'array' => 'The :attribute must have between :min and :max items.',
+ ],
+ 'boolean' => 'The :attribute field must be true or false.',
+ 'confirmed' => 'The :attribute confirmation does not match.',
+ 'date' => 'The :attribute is not a valid date.',
+ 'date_format' => 'The :attribute does not match the format :format.',
+ 'different' => 'The :attribute and :other must be different.',
+ 'digits' => 'The :attribute must be :digits digits.',
+ 'digits_between' => 'The :attribute must be between :min and :max digits.',
+ 'email' => 'The :attribute must be a valid email address.',
+ 'exists' => 'The selected :attribute is invalid.',
+ 'filled' => 'The :attribute field is required.',
+ 'image' => 'The :attribute must be an image.',
+ 'in' => 'The selected :attribute is invalid.',
+ 'integer' => 'The :attribute must be an integer.',
+ 'ip' => 'The :attribute must be a valid IP address.',
+ 'json' => 'The :attribute must be a valid JSON string.',
+ 'max' => [
+ 'numeric' => 'The :attribute may not be greater than :max.',
+ 'file' => 'The :attribute may not be greater than :max kilobytes.',
+ 'string' => 'The :attribute may not be greater than :max characters.',
+ 'array' => 'The :attribute may not have more than :max items.',
+ ],
+ 'mimes' => 'The :attribute must be a file of type: :values.',
+ 'min' => [
+ 'numeric' => 'The :attribute must be at least :min.',
+ 'file' => 'The :attribute must be at least :min kilobytes.',
+ 'string' => 'The :attribute must be at least :min characters.',
+ 'array' => 'The :attribute must have at least :min items.',
+ ],
+ 'not_in' => 'The selected :attribute is invalid.',
+ 'numeric' => 'The :attribute must be a number.',
+ 'regex' => 'The :attribute format is invalid.',
+ 'required' => 'The :attribute field is required.',
+ 'required_if' => 'The :attribute field is required when :other is :value.',
+ 'required_unless' => 'The :attribute field is required unless :other is in :values.',
+ 'required_with' => 'The :attribute field is required when :values is present.',
+ 'required_with_all' => 'The :attribute field is required when :values is present.',
+ 'required_without' => 'The :attribute field is required when :values is not present.',
+ 'required_without_all' => 'The :attribute field is required when none of :values are present.',
+ 'same' => 'The :attribute and :other must match.',
+ 'size' => [
+ 'numeric' => 'The :attribute must be :size.',
+ 'file' => 'The :attribute must be :size kilobytes.',
+ 'string' => 'The :attribute must be :size characters.',
+ 'array' => 'The :attribute must contain :size items.',
+ ],
+ 'string' => 'The :attribute must be a string.',
+ 'timezone' => 'The :attribute must be a valid zone.',
+ 'unique' => 'The :attribute has already been taken.',
+ 'url' => 'The :attribute format is invalid.',
- /*
- |--------------------------------------------------------------------------
- | Custom Validation Language Lines
- |--------------------------------------------------------------------------
- |
- | Here you may specify custom validation messages for attributes using the
- | convention "attribute.rule" to name the lines. This makes it quick to
- | specify a specific custom language line for a given attribute rule.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Custom Validation Language Lines
+ |--------------------------------------------------------------------------
+ |
+ | Here you may specify custom validation messages for attributes using the
+ | convention "attribute.rule" to name the lines. This makes it quick to
+ | specify a specific custom language line for a given attribute rule.
+ |
+ */
- 'custom' => [
- 'attribute-name' => [
- 'rule-name' => 'custom-message',
- ],
- ],
+ 'custom' => [
+ 'attribute-name' => [
+ 'rule-name' => 'custom-message',
+ ],
+ ],
- /*
- |--------------------------------------------------------------------------
- | Custom Validation Attributes
- |--------------------------------------------------------------------------
- |
- | The following language lines are used to swap attribute place-holders
- | with something more reader friendly such as E-Mail Address instead
- | of "email". This simply helps us make messages a little cleaner.
- |
- */
+ /*
+ |--------------------------------------------------------------------------
+ | Custom Validation Attributes
+ |--------------------------------------------------------------------------
+ |
+ | The following language lines are used to swap attribute place-holders
+ | with something more reader friendly such as E-Mail Address instead
+ | of "email". This simply helps us make messages a little cleaner.
+ |
+ */
- 'attributes' => [],
+ 'attributes' => [],
];
diff --git a/ruleset.xml b/ruleset.xml
deleted file mode 100644
--- a/ruleset.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0"?>
-<ruleset name="Nasqueron PHPMD rule set"
- xmlns="http://pmd.sf.net/ruleset/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
- http://pmd.sf.net/ruleset_xml_schema.xsd"
- xsi:noNamespaceSchemaLocation="
- http://pmd.sf.net/ruleset_xml_schema.xsd">
- <description>
- The PHPMD rule set for Nasqueron projects.
- </description>
-
- <rule ref="rulesets/unusedcode.xml" />
- <rule ref="rulesets/naming.xml/BooleanGetMethodName" />
- <rule ref="rulesets/naming.xml/ConstantNamingConventions" />
- <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
- <rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" />
-</ruleset>
diff --git a/server.php b/server.php
--- a/server.php
+++ b/server.php
@@ -8,14 +8,14 @@
*/
$uri = urldecode(
- parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
+ parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH )
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
-if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
- return false;
+if ( $uri !== '/' && file_exists( __DIR__ . '/public' . $uri ) ) {
+ return false;
}
-require_once __DIR__.'/public/index.php';
+require_once __DIR__ . '/public/index.php';
diff --git a/tests/Actions/AMQPActionTest.php b/tests/Actions/AMQPActionTest.php
--- a/tests/Actions/AMQPActionTest.php
+++ b/tests/Actions/AMQPActionTest.php
@@ -2,24 +2,22 @@
namespace Nasqueron\Notifications\Tests\Actions;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Actions\AMQPAction;
use Nasqueron\Notifications\Tests\TestCase;
class AMQPActionTest extends TestCase {
- protected $action;
+ protected $action;
- public function setUp () {
- $this->action = new AMQPAction(
- 'method',
- 'target'
- );
- }
+ public function setUp(): void {
+ $this->action = new AMQPAction(
+ 'method',
+ 'target'
+ );
+ }
- public function testPublicProperties () {
- $this->assertNull($this->action->error);
- $this->assertSame('AMQPAction', $this->action->action);
- }
+ public function testPublicProperties() {
+ $this->assertNull( $this->action->error );
+ $this->assertSame( 'AMQPAction', $this->action->action );
+ }
}
diff --git a/tests/Actions/ActionErrorTest.php b/tests/Actions/ActionErrorTest.php
--- a/tests/Actions/ActionErrorTest.php
+++ b/tests/Actions/ActionErrorTest.php
@@ -2,22 +2,20 @@
namespace Nasqueron\Notifications\Tests\Actions;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Actions\ActionError;
use Nasqueron\Notifications\Tests\TestCase;
class ActionErrorTest extends TestCase {
- protected $actionError;
+ protected $actionError;
- public function setUp () {
- $ex = new \RuntimeException('Lorem ipsum dolor');
- $this->actionError = new ActionError($ex);
- }
+ public function setUp(): void {
+ $ex = new \RuntimeException( 'Lorem ipsum dolor' );
+ $this->actionError = new ActionError( $ex );
+ }
- public function testPublicProperties () {
- $this->assertSame('RuntimeException', $this->actionError->type);
- $this->assertSame('Lorem ipsum dolor', $this->actionError->message);
- }
+ public function testPublicProperties() {
+ $this->assertSame( 'RuntimeException', $this->actionError->type );
+ $this->assertSame( 'Lorem ipsum dolor', $this->actionError->message );
+ }
}
diff --git a/tests/Actions/ActionsReportTest.php b/tests/Actions/ActionsReportTest.php
--- a/tests/Actions/ActionsReportTest.php
+++ b/tests/Actions/ActionsReportTest.php
@@ -2,8 +2,6 @@
namespace Nasqueron\Notifications\Tests\Actions;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Actions\ActionError;
use Nasqueron\Notifications\Actions\ActionsReport;
use Nasqueron\Notifications\Actions\AMQPAction;
@@ -11,53 +9,53 @@
class ActionsReportTest extends TestCase {
- protected $report;
-
- public function setUp () {
- $this->report = new ActionsReport();
- }
-
- public function testReport () {
- // Empty report
- $this->assertEmpty($this->report->gate);
- $this->assertEmpty($this->report->door);
- $this->assertFalse($this->report->containsError());
- $this->assertSame(0, count($this->report->actions));
-
- // Adds a first action
- // Our report should be valid.
- $action = new AMQPAction(
- 'method',
- 'target'
- );
- $this->report->addAction($action);
-
- $this->assertSame(1, count($this->report->actions));
- $this->assertFalse($this->report->containsError());
-
- // Let's attach an exception to a new action.
- // Our report should then be invalid.
- $action = new AMQPAction(
- 'methodWithException',
- 'target'
- );
- $ex = new \RuntimeException('Lorem ipsum dolor');
- $action->attachError(new ActionError($ex));
- $this->report->addAction($action);
-
- $this->assertSame(2, count($this->report->actions));
- $this->assertTrue($this->report->containsError());
-
- // Attaches to gate
- $this->report->attachToGate('QuuxGate', 'Quuxians');
- $this->assertSame('QuuxGate', $this->report->gate);
- $this->assertSame('Quuxians', $this->report->door);
-
- // Test rendering
- $actualReport = (string)$this->report;
- $expectedReport = file_get_contents(__DIR__ . '/../data/report.json');
-
- $score = similar_text($expectedReport, $actualReport);
- $this->assertGreaterThan(550, $score, 'data/report.json and rendered report differ too much. Try $this->assertEquals($expectedReport, $actualReport) to see a diff.');
- }
+ protected $report;
+
+ public function setUp(): void {
+ $this->report = new ActionsReport();
+ }
+
+ public function testReport() {
+ // Empty report
+ $this->assertEmpty( $this->report->gate );
+ $this->assertEmpty( $this->report->door );
+ $this->assertFalse( $this->report->containsError() );
+ $this->assertCount( 0, $this->report->actions );
+
+ // Adds a first action
+ // Our report should be valid.
+ $action = new AMQPAction(
+ 'method',
+ 'target'
+ );
+ $this->report->addAction( $action );
+
+ $this->assertCount( 1, $this->report->actions );
+ $this->assertFalse( $this->report->containsError() );
+
+ // Let's attach an exception to a new action.
+ // Our report should then be invalid.
+ $action = new AMQPAction(
+ 'methodWithException',
+ 'target'
+ );
+ $ex = new \RuntimeException( 'Lorem ipsum dolor' );
+ $action->attachError( new ActionError( $ex ) );
+ $this->report->addAction( $action );
+
+ $this->assertCount( 2, $this->report->actions );
+ $this->assertTrue( $this->report->containsError() );
+
+ // Attaches to gate
+ $this->report->attachToGate( 'QuuxGate', 'Quuxians' );
+ $this->assertSame( 'QuuxGate', $this->report->gate );
+ $this->assertSame( 'Quuxians', $this->report->door );
+
+ // Test rendering
+ $actualReport = (string)$this->report;
+ $expectedReport = file_get_contents( __DIR__ . '/../data/report.json' );
+
+ $score = similar_text( $expectedReport, $actualReport );
+ $this->assertGreaterThan( 550, $score, 'data/report.json and rendered report differ too much. Try $this->assertEquals($expectedReport, $actualReport) to see a diff.' );
+ }
}
diff --git a/tests/Actions/NotifyNewCommitsActionTest.php b/tests/Actions/NotifyNewCommitsActionTest.php
--- a/tests/Actions/NotifyNewCommitsActionTest.php
+++ b/tests/Actions/NotifyNewCommitsActionTest.php
@@ -2,23 +2,21 @@
namespace Nasqueron\Notifications\Tests\Actions;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Actions\NotifyNewCommitsAction;
use Nasqueron\Notifications\Tests\TestCase;
class NotifyNewCommitsActionTest extends TestCase {
- protected $action;
+ protected $action;
- public function setUp () {
- $this->action = new NotifyNewCommitsAction(
- 'QUUX'
- );
- }
+ public function setUp(): void {
+ $this->action = new NotifyNewCommitsAction(
+ 'QUUX'
+ );
+ }
- public function testPublicProperties () {
- $this->assertNull($this->action->error);
- $this->assertSame('NotifyNewCommitsAction', $this->action->action);
- }
+ public function testPublicProperties() {
+ $this->assertNull( $this->action->error );
+ $this->assertSame( 'NotifyNewCommitsAction', $this->action->action );
+ }
}
diff --git a/tests/Actions/TriggerDockerHubBuildActionTest.php b/tests/Actions/TriggerDockerHubBuildActionTest.php
--- a/tests/Actions/TriggerDockerHubBuildActionTest.php
+++ b/tests/Actions/TriggerDockerHubBuildActionTest.php
@@ -2,24 +2,22 @@
namespace Nasqueron\Notifications\Tests\Actions;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction;
use Nasqueron\Notifications\Tests\TestCase;
class TriggerDockerHubBuildActionTest extends TestCase {
- protected $action;
+ protected $action;
- public function setUp () {
- $this->action = new TriggerDockerHubBuildAction(
- 'acme/foo'
- );
- }
+ public function setUp(): void {
+ $this->action = new TriggerDockerHubBuildAction(
+ 'acme/foo'
+ );
+ }
- public function testPublicProperties () {
- $this->assertNull($this->action->error);
- $this->assertSame('acme/foo', $this->action->image);
- $this->assertSame('TriggerDockerHubBuildAction', $this->action->action);
- }
+ public function testPublicProperties() {
+ $this->assertNull( $this->action->error );
+ $this->assertSame( 'acme/foo', $this->action->image );
+ $this->assertSame( 'TriggerDockerHubBuildAction', $this->action->action );
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/CreateEventTest.php b/tests/Analyzers/GitHub/Events/CreateEventTest.php
--- a/tests/Analyzers/GitHub/Events/CreateEventTest.php
+++ b/tests/Analyzers/GitHub/Events/CreateEventTest.php
@@ -6,36 +6,34 @@
use Nasqueron\Notifications\Tests\TestCase;
class CreateEventTest extends TestCase {
- /**
- * @var CreateEvent
- */
- private $event;
-
- public function setUp () {
- $payload = new \stdClass;
- $payload->repository = new \stdClass;
- $payload->repository->full_name = 'baxterthehacker/public-repo';
- $payload->repository->html_url = 'https://github.com/baxterthehacker/public-repo';
- $payload->ref_type = 'bookmark';
- $payload->ref = 'quux';
-
- $this->event = new CreateEvent($payload);
-
- parent::setUp();
- }
-
- public function testNonExistingRefType () {
- $this->assertSame(
- "Unknown create reference: bookmark quux",
- $this->event->getDescription()
- );
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testNonExistingRefTypeLinkException () {
- $this->event->getLink();
- }
+ /**
+ * @var CreateEvent
+ */
+ private $event;
+
+ public function setUp(): void {
+ $payload = new \stdClass;
+ $payload->repository = new \stdClass;
+ $payload->repository->full_name = 'baxterthehacker/public-repo';
+ $payload->repository->html_url = 'https://github.com/baxterthehacker/public-repo';
+ $payload->ref_type = 'bookmark';
+ $payload->ref = 'quux';
+
+ $this->event = new CreateEvent( $payload );
+
+ parent::setUp();
+ }
+
+ public function testNonExistingRefType() {
+ $this->assertSame(
+ "Unknown create reference: bookmark quux",
+ $this->event->getDescription()
+ );
+ }
+
+ public function testNonExistingRefTypeLinkException() {
+ $this->expectException( \InvalidArgumentException::class );
+ $this->event->getLink();
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/DeleteEventTest.php b/tests/Analyzers/GitHub/Events/DeleteEventTest.php
--- a/tests/Analyzers/GitHub/Events/DeleteEventTest.php
+++ b/tests/Analyzers/GitHub/Events/DeleteEventTest.php
@@ -6,36 +6,34 @@
use Nasqueron\Notifications\Tests\TestCase;
class DeleteEventTest extends TestCase {
- /**
- * @var DeleteEvent
- */
- private $event;
-
- public function setUp () {
- $payload = new \stdClass;
- $payload->repository = new \stdClass;
- $payload->repository->full_name = 'baxterthehacker/public-repo';
- $payload->repository->html_url = 'https://github.com/baxterthehacker/public-repo';
- $payload->ref_type = 'bookmark';
- $payload->ref = 'quux';
-
- $this->event = new DeleteEvent($payload);
-
- parent::setUp();
- }
-
- public function testNonExistingRefType () {
- $this->assertSame(
- "Unknown delete reference: bookmark quux",
- $this->event->getDescription()
- );
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testNonExistingRefTypeLinkException () {
- $this->event->getLink();
- }
+ /**
+ * @var DeleteEvent
+ */
+ private $event;
+
+ public function setUp(): void {
+ $payload = new \stdClass;
+ $payload->repository = new \stdClass;
+ $payload->repository->full_name = 'baxterthehacker/public-repo';
+ $payload->repository->html_url = 'https://github.com/baxterthehacker/public-repo';
+ $payload->ref_type = 'bookmark';
+ $payload->ref = 'quux';
+
+ $this->event = new DeleteEvent( $payload );
+
+ parent::setUp();
+ }
+
+ public function testNonExistingRefType() {
+ $this->assertSame(
+ "Unknown delete reference: bookmark quux",
+ $this->event->getDescription()
+ );
+ }
+
+ public function testNonExistingRefTypeLinkException() {
+ $this->expectException( \InvalidArgumentException::class );
+ $this->event->getLink();
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/EventTest.php b/tests/Analyzers/GitHub/Events/EventTest.php
--- a/tests/Analyzers/GitHub/Events/EventTest.php
+++ b/tests/Analyzers/GitHub/Events/EventTest.php
@@ -7,102 +7,100 @@
class EventTest extends TestCase {
- public function testGetClass () {
- $this->assertSame(
- 'Nasqueron\Notifications\Analyzers\GitHub\Events\CommitCommentEvent',
- Event::getClass('commit_comment')
- );
- }
+ public function testGetClass() {
+ $this->assertSame(
+ 'Nasqueron\Notifications\Analyzers\GitHub\Events\CommitCommentEvent',
+ Event::getClass( 'commit_comment' )
+ );
+ }
- public function testForPayload () {
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Analyzers\GitHub\Events\CommitCommentEvent',
- Event::forPayload('commit_comment', new \stdClass)
- );
- }
+ public function testForPayload() {
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Analyzers\GitHub\Events\CommitCommentEvent',
+ Event::forPayload( 'commit_comment', new \stdClass )
+ );
+ }
- /**
- * @expectedException InvalidArgumentException
- */
- public function testForPayloadWithException () {
- Event::forPayload('not_existing', new \stdClass);
- }
+ public function testForPayloadWithException() {
+ $this->expectException( \InvalidArgumentException::class );
+ Event::forPayload( 'not_existing', new \stdClass );
+ }
- public function testCut () {
- $this->assertSame('', Event::cut(''));
- $this->assertSame('', Event::cut('', 0));
- $this->assertSame('…', Event::cut('Lorem ipsum dolor', 0));
- $this->assertSame('Lorem…', Event::cut('Lorem ipsum dolor', 6));
- $this->assertSame('Lorem ipsum dolor', Event::cut('Lorem ipsum dolor'));
- }
+ public function testCut() {
+ $this->assertSame( '', Event::cut( '' ) );
+ $this->assertSame( '', Event::cut( '', 0 ) );
+ $this->assertSame( '…', Event::cut( 'Lorem ipsum dolor', 0 ) );
+ $this->assertSame( 'Lorem…', Event::cut( 'Lorem ipsum dolor', 6 ) );
+ $this->assertSame( 'Lorem ipsum dolor', Event::cut( 'Lorem ipsum dolor' ) );
+ }
- /**
- * @dataProvider payloadDescriptionProvider
- */
- public function testGetDescriptionAndLink ($eventName,
- $expectedDescription,
- $expectedLink) {
- $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/$eventName.json";
- $payload = json_decode(file_get_contents($filename));
- $event = Event::forPayload($eventName, $payload);
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testGetDescriptionAndLink( string $eventName,
+ string $expectedDescription,
+ string $expectedLink ) {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/$eventName.json";
+ $payload = json_decode( file_get_contents( $filename ) );
+ $event = Event::forPayload( $eventName, $payload );
- $this->assertSame($expectedDescription, $event->getDescription());
- $this->assertSame($expectedLink, $event->getLink());
- }
+ $this->assertSame( $expectedDescription, $event->getDescription() );
+ $this->assertSame( $expectedLink, $event->getLink() );
+ }
- public function payloadDescriptionProvider () {
- return [
- 'CommitCommentEvent' => [
- 'commit_comment',
- 'baxterthehacker added a comment to 9049f126: This is a really good change! :+1:',
- 'https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394'
- ],
- 'CreateEvent' => [
- 'create',
- 'New tag on baxterthehacker/public-repo: 0.0.1',
- 'https://github.com/baxterthehacker/public-repo/releases/tag/0.0.1'
- ],
- 'DeleteEvent' => [
- 'delete',
- 'Removed tag on baxterthehacker/public-repo: simple-tag',
- 'https://github.com/baxterthehacker/public-repo/tags'
- ],
- 'IssueCommentEvent' => [
- 'issue_comment',
- "baxterthehacker added a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away.",
- 'https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140'
- ],
- 'ForkEvent' => [
- 'fork',
- 'baxterthehacker/public-repo has been forked to baxterandthehackers/public-repo',
- 'https://github.com/baxterandthehackers/public-repo'
- ],
- 'PullRequestEvent' => [
- 'pull_request',
- 'baxterthehacker has opened a pull request: #1 — Update the README with new information',
- 'https://github.com/baxterthehacker/public-repo/pull/1'
- ],
- 'PushEvent' => [
- 'push',
- 'baxterthehacker committed Update README.md',
- 'https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c'
- ],
- 'RepositoryEvent' => [
- 'repository',
- 'New repository baxterandthehackers/new-repository',
- 'https://github.com/baxterandthehackers/new-repository'
- ],
- 'StatusEvent' => [
- 'status',
- 'Status of 9049f126: default — success',
- ''
- ],
- 'WatchEvent' => [
- 'watch',
- 'baxterthehacker starred baxterthehacker/public-repo',
- 'https://github.com/baxterthehacker'
- ],
- ];
- }
+ public function payloadDescriptionProvider() {
+ return [
+ 'CommitCommentEvent' => [
+ 'commit_comment',
+ 'baxterthehacker added a comment to 9049f126: This is a really good change! :+1:',
+ 'https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394'
+ ],
+ 'CreateEvent' => [
+ 'create',
+ 'New tag on baxterthehacker/public-repo: 0.0.1',
+ 'https://github.com/baxterthehacker/public-repo/releases/tag/0.0.1'
+ ],
+ 'DeleteEvent' => [
+ 'delete',
+ 'Removed tag on baxterthehacker/public-repo: simple-tag',
+ 'https://github.com/baxterthehacker/public-repo/tags'
+ ],
+ 'IssueCommentEvent' => [
+ 'issue_comment',
+ "baxterthehacker added a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away.",
+ 'https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140'
+ ],
+ 'ForkEvent' => [
+ 'fork',
+ 'baxterthehacker/public-repo has been forked to baxterandthehackers/public-repo',
+ 'https://github.com/baxterandthehackers/public-repo'
+ ],
+ 'PullRequestEvent' => [
+ 'pull_request',
+ 'baxterthehacker has opened a pull request: #1 — Update the README with new information',
+ 'https://github.com/baxterthehacker/public-repo/pull/1'
+ ],
+ 'PushEvent' => [
+ 'push',
+ 'baxterthehacker committed Update README.md',
+ 'https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c'
+ ],
+ 'RepositoryEvent' => [
+ 'repository',
+ 'New repository baxterandthehackers/new-repository',
+ 'https://github.com/baxterandthehackers/new-repository'
+ ],
+ 'StatusEvent' => [
+ 'status',
+ 'Status of 9049f126: default — success',
+ ''
+ ],
+ 'WatchEvent' => [
+ 'watch',
+ 'baxterthehacker starred baxterthehacker/public-repo',
+ 'https://github.com/baxterthehacker'
+ ],
+ ];
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php b/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php
--- a/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php
+++ b/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php
@@ -7,38 +7,38 @@
class IssueCommentEventTest extends TestCase {
- /**
- * @var \stdClass
- */
- private $payload;
-
- public function setUp () {
- $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/issue_comment.json";
- $this->payload = json_decode(file_get_contents($filename));
-
- parent::setUp();
- }
-
- /**
- * @dataProvider payloadDescriptionProvider
- */
- public function testWhenRepositoryPerAction ($action, $description) {
- $this->payload->action = $action;
- $event = new IssueCommentEvent($this->payload);
- $this->assertSame($description, $event->getDescription());
- }
-
- /**
- * Provides actions and descritions for testWhenRepositoryPerAction
- *
- * See https://developer.github.com/v3/activity/events/types/#issuecommentevent
- */
- public function payloadDescriptionProvider () {
- return [
- ['created', "baxterthehacker added a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away."],
- ['edited', "baxterthehacker edited a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away."],
- ['deleted', "baxterthehacker deleted a comment to issue #2 — Spelling error in the README file"],
- ];
- }
+ /**
+ * @var \stdClass
+ */
+ private $payload;
+
+ public function setUp(): void {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/issue_comment.json";
+ $this->payload = json_decode( file_get_contents( $filename ) );
+
+ parent::setUp();
+ }
+
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testWhenRepositoryPerAction( string $action, string $description ) {
+ $this->payload->action = $action;
+ $event = new IssueCommentEvent( $this->payload );
+ $this->assertSame( $description, $event->getDescription() );
+ }
+
+ /**
+ * Provides actions and descritions for testWhenRepositoryPerAction
+ *
+ * See https://developer.github.com/v3/activity/events/types/#issuecommentevent
+ */
+ public function payloadDescriptionProvider() {
+ return [
+ [ 'created', "baxterthehacker added a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away." ],
+ [ 'edited', "baxterthehacker edited a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away." ],
+ [ 'deleted', "baxterthehacker deleted a comment to issue #2 — Spelling error in the README file" ],
+ ];
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/PullRequestEventTest.php b/tests/Analyzers/GitHub/Events/PullRequestEventTest.php
--- a/tests/Analyzers/GitHub/Events/PullRequestEventTest.php
+++ b/tests/Analyzers/GitHub/Events/PullRequestEventTest.php
@@ -7,44 +7,44 @@
class PullRequestEventTest extends TestCase {
- /**
- * @var \stdClass
- */
- private $payload;
-
- public function setUp () {
- $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/pull_request.json";
- $this->payload = json_decode(file_get_contents($filename));
-
- parent::setUp();
- }
-
- /**
- * @dataProvider payloadDescriptionProvider
- */
- public function testWhenRepositoryPerAction ($action, $description) {
- $this->payload->action = $action;
- $event = new PullRequestEvent($this->payload);
- $this->assertSame($description, $event->getDescription());
- }
-
- /**
- * Provides actions and descritions for testWhenRepositoryPerAction
- *
- * See https://developer.github.com/v3/activity/events/types/#pullrequestevent
- */
- public function payloadDescriptionProvider () {
- return [
- ['assigned', "baxterthehacker has assigned the pull request #1 — Update the README with new information to alken-orin"],
- ['unassigned', "baxterthehacker has edited the assignees from the pull request #1 — Update the README with new information"],
- ['labeled', "baxterthehacker has labeled the pull request #1 — Update the README with new information"],
- ['unlabeled', "baxterthehacker has removed a label from the pull request #1 — Update the README with new information"],
- ['opened', "baxterthehacker has opened a pull request: #1 — Update the README with new information"],
- ['edited', "baxterthehacker has edited the pull request #1 — Update the README with new information"],
- ['closed', "baxterthehacker has closed the pull request #1 — Update the README with new information"],
- ['reopened', "baxterthehacker has reopened the pull request #1 — Update the README with new information"],
- ['quuxed', "Unknown pull request action: quuxed"],
- ];
- }
+ /**
+ * @var \stdClass
+ */
+ private $payload;
+
+ public function setUp(): void {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/pull_request.json";
+ $this->payload = json_decode( file_get_contents( $filename ) );
+
+ parent::setUp();
+ }
+
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testWhenRepositoryPerAction( string $action, string $description ) {
+ $this->payload->action = $action;
+ $event = new PullRequestEvent( $this->payload );
+ $this->assertSame( $description, $event->getDescription() );
+ }
+
+ /**
+ * Provides actions and descritions for testWhenRepositoryPerAction
+ *
+ * See https://developer.github.com/v3/activity/events/types/#pullrequestevent
+ */
+ public function payloadDescriptionProvider() {
+ return [
+ [ 'assigned', "baxterthehacker has assigned the pull request #1 — Update the README with new information to alken-orin" ],
+ [ 'unassigned', "baxterthehacker has edited the assignees from the pull request #1 — Update the README with new information" ],
+ [ 'labeled', "baxterthehacker has labeled the pull request #1 — Update the README with new information" ],
+ [ 'unlabeled', "baxterthehacker has removed a label from the pull request #1 — Update the README with new information" ],
+ [ 'opened', "baxterthehacker has opened a pull request: #1 — Update the README with new information" ],
+ [ 'edited', "baxterthehacker has edited the pull request #1 — Update the README with new information" ],
+ [ 'closed', "baxterthehacker has closed the pull request #1 — Update the README with new information" ],
+ [ 'reopened', "baxterthehacker has reopened the pull request #1 — Update the README with new information" ],
+ [ 'quuxed', "Unknown pull request action: quuxed" ],
+ ];
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/PushEventTest.php b/tests/Analyzers/GitHub/Events/PushEventTest.php
--- a/tests/Analyzers/GitHub/Events/PushEventTest.php
+++ b/tests/Analyzers/GitHub/Events/PushEventTest.php
@@ -7,93 +7,92 @@
class PushEventTest extends TestCase {
- /**
- * @var \stdClass[]
- */
- private $payloads;
-
- public function setUp () {
- $payloadsToPrepare = [
- '0' => 'GitHubPushForceZeroPayload.json',
- '1' => 'GitHubEvents/push.json',
- 'n' => 'GitHubPushSeveralCommitsPayload.json',
- ];
-
- foreach ($payloadsToPrepare as $key => $filename) {
- $filename = __DIR__ . "/../../../data/payloads/" . $filename;
- $this->payloads[$key] = json_decode(file_get_contents($filename));
- }
-
- parent::setUp();
- }
-
- ///
- /// WithRepoAndBranch trait
- ///
-
-
- public function testGetRepositoryAndBranch () {
- $this->assertSame("", PushEvent::getRepositoryAndBranch("", "master"));
- $this->assertSame("", PushEvent::getRepositoryAndBranch("", "foo"));
- $this->assertSame("quux", PushEvent::getRepositoryAndBranch("quux", "master"));
- $this->assertSame("quux", PushEvent::getRepositoryAndBranch("quux", "refs/heads/master"));
- $this->assertSame("quux", PushEvent::getRepositoryAndBranch("quux", ""));
- $this->assertSame("quux (branch foo)", PushEvent::getRepositoryAndBranch("quux", "refs/heads/foo"));
- $this->assertSame("quux (branch feature/foo)", PushEvent::getRepositoryAndBranch("quux", "refs/heads/feature/foo"));
- $this->assertSame("quux (branch feature/foo)", PushEvent::getRepositoryAndBranch("quux", "feature/foo"));
- $this->assertSame("quux (branch foo)", PushEvent::getRepositoryAndBranch("quux", "foo"));
- $this->assertSame("quux (branch 0)", PushEvent::getRepositoryAndBranch("quux", "0"));
- }
-
- ///
- /// WithCommit trait
- ///
-
- public function testGetCommitTitle () {
- $this->assertSame("", PushEvent::getCommitTitle(""));
- $this->assertSame("Lorem ipsum dolor", PushEvent::getCommitTitle("Lorem ipsum dolor"));
-
- $longCommitMessages = [
- "I was born in a water moon. Some people, especially its inhabitants, called it a planet, but as it was only a little over two hundred kilometres in diameter, 'moon' seems the more accurate term. The moon was made entirely of water, by which I mean it was a globe that not only had no land, but no rock either, a sphere with no solid core at all, just liquid water, all the way down to the very centre of the globe.",
- "I was born in a water moon. Some people, especially its inhabitants, called it a planet, but as it was only a little over two hundred kilometres in diameter, 'moon' seems the more accurate term. The moon was made entirely of water, by which I mean it was a globe that not only had no land, but no rock either, a sphere with no solid core at all, just liquid water, all the way down to the very centre of the globe.\n\nIf it had been much bigger the moon would have had a core of ice, for water, though supposedly incompressible, is not entirely so, and will change under extremes of pressure to become ice. (If you are used to living on a planet where ice floats on the surface of water, this seems odd and even wrong, but nevertheless it is the case.) The moon was not quite of a size for an ice core to form, and therefore one could, if one was sufficiently hardy, and adequately proof against the water pressure, make one's way down, through the increasing weight of water above, to the very centre of the moon.",
- ];
- $shortCommitTitle = "I was born in a water moon. Some people, especially its inhabitants, ca…";
- foreach ($longCommitMessages as $longCommitMessage) {
- $this->assertSame(
- $shortCommitTitle,
- PushEvent::getCommitTitle($longCommitMessage)
- );
- }
- }
-
- public function testWhenTheCommitterAndAuthorAreDifferent () {
- $payload = clone $this->payloads['1'];
- $payload->head_commit->author->username = "Skrunge";
- $event = new PushEvent($payload);
-
- $this->assertSame(
- "baxterthehacker committed Update README.md (authored by Skrunge)",
- $event->getDescription()
- );
- }
-
- public function testOnGitPushForce () {
- $event = new PushEvent($this->payloads['0']);
-
- $this->assertSame(
- "dereckson forcely updated docker-nginx-php-fpm (branch novolume)",
- $event->getDescription()
- );
- $this->assertContains("compare", $event->getLink());
- }
-
- public function testOnGitPushWithSeveralCommits () {
- $event = new PushEvent($this->payloads['n']);
-
- $this->assertSame(
- "dereckson pushed 2 commits to notifications",
- $event->getDescription()
- );
- $this->assertContains("compare", $event->getLink());
- }
+ /**
+ * @var \stdClass[]
+ */
+ private $payloads;
+
+ public function setUp(): void {
+ $payloadsToPrepare = [
+ '0' => 'GitHubPushForceZeroPayload.json',
+ '1' => 'GitHubEvents/push.json',
+ 'n' => 'GitHubPushSeveralCommitsPayload.json',
+ ];
+
+ foreach ( $payloadsToPrepare as $key => $filename ) {
+ $filename = __DIR__ . "/../../../data/payloads/" . $filename;
+ $this->payloads[$key] = json_decode( file_get_contents( $filename ) );
+ }
+
+ parent::setUp();
+ }
+
+ ///
+ /// WithRepoAndBranch trait
+ ///
+
+ public function testGetRepositoryAndBranch() {
+ $this->assertSame( "", PushEvent::getRepositoryAndBranch( "", "master" ) );
+ $this->assertSame( "", PushEvent::getRepositoryAndBranch( "", "foo" ) );
+ $this->assertSame( "quux", PushEvent::getRepositoryAndBranch( "quux", "master" ) );
+ $this->assertSame( "quux", PushEvent::getRepositoryAndBranch( "quux", "refs/heads/master" ) );
+ $this->assertSame( "quux", PushEvent::getRepositoryAndBranch( "quux", "" ) );
+ $this->assertSame( "quux (branch foo)", PushEvent::getRepositoryAndBranch( "quux", "refs/heads/foo" ) );
+ $this->assertSame( "quux (branch feature/foo)", PushEvent::getRepositoryAndBranch( "quux", "refs/heads/feature/foo" ) );
+ $this->assertSame( "quux (branch feature/foo)", PushEvent::getRepositoryAndBranch( "quux", "feature/foo" ) );
+ $this->assertSame( "quux (branch foo)", PushEvent::getRepositoryAndBranch( "quux", "foo" ) );
+ $this->assertSame( "quux (branch 0)", PushEvent::getRepositoryAndBranch( "quux", "0" ) );
+ }
+
+ ///
+ /// WithCommit trait
+ ///
+
+ public function testGetCommitTitle() {
+ $this->assertSame( "", PushEvent::getCommitTitle( "" ) );
+ $this->assertSame( "Lorem ipsum dolor", PushEvent::getCommitTitle( "Lorem ipsum dolor" ) );
+
+ $longCommitMessages = [
+ "I was born in a water moon. Some people, especially its inhabitants, called it a planet, but as it was only a little over two hundred kilometres in diameter, 'moon' seems the more accurate term. The moon was made entirely of water, by which I mean it was a globe that not only had no land, but no rock either, a sphere with no solid core at all, just liquid water, all the way down to the very centre of the globe.",
+ "I was born in a water moon. Some people, especially its inhabitants, called it a planet, but as it was only a little over two hundred kilometres in diameter, 'moon' seems the more accurate term. The moon was made entirely of water, by which I mean it was a globe that not only had no land, but no rock either, a sphere with no solid core at all, just liquid water, all the way down to the very centre of the globe.\n\nIf it had been much bigger the moon would have had a core of ice, for water, though supposedly incompressible, is not entirely so, and will change under extremes of pressure to become ice. (If you are used to living on a planet where ice floats on the surface of water, this seems odd and even wrong, but nevertheless it is the case.) The moon was not quite of a size for an ice core to form, and therefore one could, if one was sufficiently hardy, and adequately proof against the water pressure, make one's way down, through the increasing weight of water above, to the very centre of the moon.",
+ ];
+ $shortCommitTitle = "I was born in a water moon. Some people, especially its inhabitants, ca…";
+ foreach ( $longCommitMessages as $longCommitMessage ) {
+ $this->assertSame(
+ $shortCommitTitle,
+ PushEvent::getCommitTitle( $longCommitMessage )
+ );
+ }
+ }
+
+ public function testWhenTheCommitterAndAuthorAreDifferent() {
+ $payload = clone $this->payloads['1'];
+ $payload->head_commit->author->username = "Skrunge";
+ $event = new PushEvent( $payload );
+
+ $this->assertSame(
+ "baxterthehacker committed Update README.md (authored by Skrunge)",
+ $event->getDescription()
+ );
+ }
+
+ public function testOnGitPushForce() {
+ $event = new PushEvent( $this->payloads['0'] );
+
+ $this->assertSame(
+ "dereckson forcely updated docker-nginx-php-fpm (branch novolume)",
+ $event->getDescription()
+ );
+ $this->assertStringContainsString( "compare", $event->getLink() );
+ }
+
+ public function testOnGitPushWithSeveralCommits() {
+ $event = new PushEvent( $this->payloads['n'] );
+
+ $this->assertSame(
+ "dereckson pushed 2 commits to notifications",
+ $event->getDescription()
+ );
+ $this->assertStringContainsString( "compare", $event->getLink() );
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
--- a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
+++ b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
@@ -7,66 +7,66 @@
class RepositoryEventTest extends TestCase {
- /**
- * @var \stdClass
- */
- private $payload;
+ /**
+ * @var \stdClass
+ */
+ private $payload;
- public function setUp () {
- $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/repository.json";
- $this->payload = json_decode(file_get_contents($filename));
+ public function setUp(): void {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/repository.json";
+ $this->payload = json_decode( file_get_contents( $filename ) );
- parent::setUp();
- }
+ parent::setUp();
+ }
- public function testWhenRepositoryIsForked () {
- $payload = clone $this->payload;
- $payload->repository->fork = true;
- $event = new RepositoryEvent($payload);
+ public function testWhenRepositoryIsForked() {
+ $payload = clone $this->payload;
+ $payload->repository->fork = true;
+ $event = new RepositoryEvent( $payload );
- $this->assertContains("fork", $event->getDescription());
- }
+ $this->assertStringContainsString( "fork", $event->getDescription() );
+ }
- public function testWhenRepositoryContainsDescription () {
- $payload = clone $this->payload;
- $payload->repository->description = "Lorem ipsum dolor";
- $event = new RepositoryEvent($payload);
+ public function testWhenRepositoryContainsDescription() {
+ $payload = clone $this->payload;
+ $payload->repository->description = "Lorem ipsum dolor";
+ $event = new RepositoryEvent( $payload );
- $this->assertContains("Lorem ipsum dolor", $event->getDescription());
- }
+ $this->assertStringContainsString( "Lorem ipsum dolor", $event->getDescription() );
+ }
- public function testWhenRepositoryIsForkedAndContainsDescription () {
- $payload = clone $this->payload;
- $payload->repository->fork = true;
- $payload->repository->description = "Lorem ipsum dolor";
- $event = new RepositoryEvent($payload);
+ public function testWhenRepositoryIsForkedAndContainsDescription() {
+ $payload = clone $this->payload;
+ $payload->repository->fork = true;
+ $payload->repository->description = "Lorem ipsum dolor";
+ $event = new RepositoryEvent( $payload );
- $this->assertContains("fork", $event->getDescription());
- $this->assertContains("Lorem ipsum dolor", $event->getDescription());
- }
+ $this->assertStringContainsString( "fork", $event->getDescription() );
+ $this->assertStringContainsString( "Lorem ipsum dolor", $event->getDescription() );
+ }
- /**
- * @dataProvider payloadDescriptionProvider
- */
- public function testWhenRepositoryPerAction ($action, $description) {
- $this->payload->action = $action;
- $event = new RepositoryEvent($this->payload);
- $this->assertSame($description, $event->getDescription());
- }
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testWhenRepositoryPerAction( string $action, string $description ) {
+ $this->payload->action = $action;
+ $event = new RepositoryEvent( $this->payload );
+ $this->assertSame( $description, $event->getDescription() );
+ }
- /**
- * Provides actions and descritions for testWhenRepositoryPerAction
- *
- * See https://developer.github.com/v3/activity/events/types/#repositoryevent
- */
- public function payloadDescriptionProvider () {
- return [
- ['created', "New repository baxterandthehackers/new-repository"],
- ['deleted', "Repository baxterandthehackers/new-repository deleted (danger zone)"],
- ['publicized', "Repository baxterandthehackers/new-repository is now public"],
- ['privatized', "Repository baxterandthehackers/new-repository is now private"],
- ['quuxed', "Unknown repository action: quuxed"],
- ];
- }
+ /**
+ * Provides actions and descritions for testWhenRepositoryPerAction
+ *
+ * See https://developer.github.com/v3/activity/events/types/#repositoryevent
+ */
+ public function payloadDescriptionProvider() {
+ return [
+ [ 'created', "New repository baxterandthehackers/new-repository" ],
+ [ 'deleted', "Repository baxterandthehackers/new-repository deleted (danger zone)" ],
+ [ 'publicized', "Repository baxterandthehackers/new-repository is now public" ],
+ [ 'privatized', "Repository baxterandthehackers/new-repository is now private" ],
+ [ 'quuxed', "Unknown repository action: quuxed" ],
+ ];
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/StatusEventTest.php b/tests/Analyzers/GitHub/Events/StatusEventTest.php
--- a/tests/Analyzers/GitHub/Events/StatusEventTest.php
+++ b/tests/Analyzers/GitHub/Events/StatusEventTest.php
@@ -7,27 +7,27 @@
class StatusEventTest extends TestCase {
- /**
- * @var \stdClass
- */
- private $payload;
-
- public function setUp () {
- $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/status.json";
- $this->payload = json_decode(file_get_contents($filename));
-
- parent::setUp();
- }
-
- public function testWhenStatusContainsUrl () {
- $payload = clone $this->payload;
- $payload->target_url = "http://www.perdu.com/";
- $event = new StatusEvent($payload);
-
- $this->assertSame(
- "http://www.perdu.com/",
- $event->getLink()
- );
- }
+ /**
+ * @var \stdClass
+ */
+ private $payload;
+
+ public function setUp(): void {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/status.json";
+ $this->payload = json_decode( file_get_contents( $filename ) );
+
+ parent::setUp();
+ }
+
+ public function testWhenStatusContainsUrl() {
+ $payload = clone $this->payload;
+ $payload->target_url = "http://www.perdu.com/";
+ $event = new StatusEvent( $payload );
+
+ $this->assertSame(
+ "http://www.perdu.com/",
+ $event->getLink()
+ );
+ }
}
diff --git a/tests/Analyzers/GitHub/Events/UnknownEventTest.php b/tests/Analyzers/GitHub/Events/UnknownEventTest.php
--- a/tests/Analyzers/GitHub/Events/UnknownEventTest.php
+++ b/tests/Analyzers/GitHub/Events/UnknownEventTest.php
@@ -7,22 +7,22 @@
class UnknownEventTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Analyzers\GitHub\Events\UnknownEvent
- */
- private $event;
+ /**
+ * @var \Nasqueron\Notifications\Analyzers\GitHub\Events\UnknownEvent
+ */
+ private $event;
- public function setUp () {
- $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/push.json";
- $payload = json_decode(file_get_contents($filename));
- $this->event = new UnknownEvent("quux", $payload);
+ public function setUp(): void {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/push.json";
+ $payload = json_decode( file_get_contents( $filename ) );
+ $this->event = new UnknownEvent( "quux", $payload );
- parent::setUp();
- }
+ parent::setUp();
+ }
- public function testUnknownEvent () {
- $this->assertInstanceOf("Nasqueron\Notifications\Analyzers\GitHub\Events\UnknownEvent", $this->event);
- $this->assertSame("Some quux happened", $this->event->getDescription());
- $this->assertEmpty($this->event->getLink());
- }
+ public function testUnknownEvent() {
+ $this->assertInstanceOf( "Nasqueron\Notifications\Analyzers\GitHub\Events\UnknownEvent", $this->event );
+ $this->assertSame( "Some quux happened", $this->event->getDescription() );
+ $this->assertEmpty( $this->event->getLink() );
+ }
}
diff --git a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php
--- a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php
+++ b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php
@@ -7,134 +7,127 @@
class GitHubPayloadAnalyzerTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
- */
- private $unknownEventAnalyzer;
-
- /**
- * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
- */
- private $pingAnalyzer;
-
- /**
- * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
- */
- private $pushAnalyzer;
-
- /**
- * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
- */
- private $pushToMappedRepositoryAnalyzer;
-
- /**
- * Prepares the tests
- */
- public function setUp () {
- parent::setUp();
-
- $this->unknownEventAnalyzer = new GitHubPayloadAnalyzer(
- "Acme", // Expected without known config file
- "quux",
- new \stdClass
- );
-
- $this->pingAnalyzer = new GitHubPayloadAnalyzer(
- "Nasqueron", // Expected with known config file
- "ping",
- new \stdClass
- );
-
- $filename = __DIR__ . "/../../data/payloads/GitHubEvents/push.json";
- $payloadRawContent = file_get_contents($filename);
-
- $payload = json_decode($payloadRawContent);
- $this->pushAnalyzer = new GitHubPayloadAnalyzer(
- "Nasqueron", // Expected with known config
- "push",
- $payload
- );
-
- $dockerPayload = json_decode($payloadRawContent);
- $dockerPayload->repository->name = "docker-someapp";
- $this->pushToMappedRepositoryAnalyzer = new GitHubPayloadAnalyzer(
- "Nasqueron", // Expected with known config
- "push",
- $dockerPayload
- );
- }
-
- ///
- /// Test constructor
- ///
-
- /**
- * @expectedException TypeError
- */
- public function testConstructorThrowsAnExceptionWhenPayloadIsInvalid () {
- new GitHubPayloadAnalyzer(
- "Acme",
- "push",
- "This is not an object deserialized from JSON but a string."
- );
- }
-
- ///
- /// Test getConfigurationFileName
- ///
-
- public function testGetConfigurationFileNameWhenConfigExists () {
- $this->assertSame(
- "GitHubPayloadAnalyzer/Nasqueron.json",
- $this->pingAnalyzer->getConfigurationFileName()
- );
- }
-
- public function testGetConfigurationFileNameWhenConfigDoesNotExist () {
- $this->assertSame(
- "GitHubPayloadAnalyzer/default.json",
- $this->unknownEventAnalyzer->getConfigurationFileName()
- );
- }
-
- ///
- /// Test getItemName
- ///
-
- public function testGetItemNameWhenEventIsAdministrative () {
- $this->assertEmpty($this->pingAnalyzer->getItemName());
- }
-
- public function testGetItemNameWhenEventIsRepositoryRelative () {
- $this->assertSame("public-repo", $this->pushAnalyzer->getItemName());
- }
-
- ///
- /// Test getGroup
- ///
-
- public function testGetGroupWhenEventIsAdministrative () {
- $this->assertSame("orgz", $this->pingAnalyzer->getGroup());
- }
-
- public function testGetGroupOnPushToMappedRepository () {
- $this->assertSame("docker", $this->pushToMappedRepositoryAnalyzer->getGroup());
-
- }
-
- public function testGetGroupOnPushToNotMappedRepository () {
- $this->assertSame("nasqueron", $this->pushAnalyzer->getGroup());
- }
-
- ///
- /// Test if our fallback is correct when the GitHub event type is unknown
- ///
-
- public function testDescriptionContainsTypeWhenEventTypeIsUnknown () {
- $this->assertContains(
- "quux",
- $this->unknownEventAnalyzer->getDescription()
- );
- }
+ /**
+ * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
+ */
+ private $unknownEventAnalyzer;
+
+ /**
+ * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
+ */
+ private $pingAnalyzer;
+
+ /**
+ * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
+ */
+ private $pushAnalyzer;
+
+ /**
+ * @var \Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
+ */
+ private $pushToMappedRepositoryAnalyzer;
+
+ /**
+ * Prepares the tests
+ */
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->unknownEventAnalyzer = new GitHubPayloadAnalyzer(
+ "Acme", // Expected without known config file
+ "quux",
+ new \stdClass
+ );
+
+ $this->pingAnalyzer = new GitHubPayloadAnalyzer(
+ "Nasqueron", // Expected with known config file
+ "ping",
+ new \stdClass
+ );
+
+ $filename = __DIR__ . "/../../data/payloads/GitHubEvents/push.json";
+ $payloadRawContent = file_get_contents( $filename );
+
+ $payload = json_decode( $payloadRawContent );
+ $this->pushAnalyzer = new GitHubPayloadAnalyzer(
+ "Nasqueron", // Expected with known config
+ "push",
+ $payload
+ );
+
+ $dockerPayload = json_decode( $payloadRawContent );
+ $dockerPayload->repository->name = "docker-someapp";
+ $this->pushToMappedRepositoryAnalyzer = new GitHubPayloadAnalyzer(
+ "Nasqueron", // Expected with known config
+ "push",
+ $dockerPayload
+ );
+ }
+
+ public function testConstructorThrowsAnExceptionWhenPayloadIsInvalid() {
+ $this->expectException( \TypeError::class );
+ new GitHubPayloadAnalyzer(
+ "Acme",
+ "push",
+ "This is not an object deserialized from JSON but a string."
+ );
+ }
+
+ ///
+ /// Test getConfigurationFileName
+ ///
+
+ public function testGetConfigurationFileNameWhenConfigExists() {
+ $this->assertSame(
+ "GitHubPayloadAnalyzer/Nasqueron.json",
+ $this->pingAnalyzer->getConfigurationFileName()
+ );
+ }
+
+ public function testGetConfigurationFileNameWhenConfigDoesNotExist() {
+ $this->assertSame(
+ "GitHubPayloadAnalyzer/default.json",
+ $this->unknownEventAnalyzer->getConfigurationFileName()
+ );
+ }
+
+ ///
+ /// Test getItemName
+ ///
+
+ public function testGetItemNameWhenEventIsAdministrative() {
+ $this->assertEmpty( $this->pingAnalyzer->getItemName() );
+ }
+
+ public function testGetItemNameWhenEventIsRepositoryRelative() {
+ $this->assertSame( "public-repo", $this->pushAnalyzer->getItemName() );
+ }
+
+ ///
+ /// Test getGroup
+ ///
+
+ public function testGetGroupWhenEventIsAdministrative() {
+ $this->assertSame( "orgz", $this->pingAnalyzer->getGroup() );
+ }
+
+ public function testGetGroupOnPushToMappedRepository() {
+ $this->assertSame( "docker", $this->pushToMappedRepositoryAnalyzer->getGroup() );
+ }
+
+ public function testGetGroupOnPushToNotMappedRepository() {
+ $this->assertSame( "nasqueron", $this->pushAnalyzer->getGroup() );
+ }
+
+ ///
+ /// Test if our fallback is correct when the GitHub event type is unknown
+ ///
+
+ public function testDescriptionContainsTypeWhenEventTypeIsUnknown() {
+ $this->assertStringContainsString(
+ "quux",
+ $this->unknownEventAnalyzer->getDescription()
+ );
+ }
}
diff --git a/tests/Analyzers/ItemGroupMappingTest.php b/tests/Analyzers/ItemGroupMappingTest.php
--- a/tests/Analyzers/ItemGroupMappingTest.php
+++ b/tests/Analyzers/ItemGroupMappingTest.php
@@ -2,77 +2,75 @@
namespace Nasqueron\Notifications\Tests\Analyzers;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
class ItemGroupMappingTest extends TestCase {
- public function testDoesItemMatch () {
- $this->assertTrue(
- ItemGroupMapping::doesItemMatch(
- 'quux*',
- 'quuxians'
- )
- );
+ public function testDoesItemMatch() {
+ $this->assertTrue(
+ ItemGroupMapping::doesItemMatch(
+ 'quux*',
+ 'quuxians'
+ )
+ );
- $this->assertTrue(
- ItemGroupMapping::doesItemMatch(
- 'quux*',
- 'quux'
- )
- );
+ $this->assertTrue(
+ ItemGroupMapping::doesItemMatch(
+ 'quux*',
+ 'quux'
+ )
+ );
- $this->assertFalse(
- ItemGroupMapping::doesItemMatch(
- 'foobar',
- 'quux'
- )
- );
+ $this->assertFalse(
+ ItemGroupMapping::doesItemMatch(
+ 'foobar',
+ 'quux'
+ )
+ );
- $this->assertFalse(
- ItemGroupMapping::doesItemMatch(
- '',
- 'quuxians'
- )
- );
+ $this->assertFalse(
+ ItemGroupMapping::doesItemMatch(
+ '',
+ 'quuxians'
+ )
+ );
- $this->assertFalse(
- ItemGroupMapping::doesItemMatch(
- 'quux*',
- ''
- )
- );
- }
+ $this->assertFalse(
+ ItemGroupMapping::doesItemMatch(
+ 'quux*',
+ ''
+ )
+ );
+ }
- /**
- * @dataProvider payloadProvider
- */
- public function testDeserialize (ItemGroupMapping $payload, ItemGroupMapping $expected) {
- $this->assertEquals($payload, $expected);
- }
+ /**
+ * @dataProvider payloadProvider
+ */
+ public function testDeserialize( ItemGroupMapping $payload, ItemGroupMapping $expected ) {
+ $this->assertEquals( $payload, $expected );
+ }
- private function deserialize ($file) : ItemGroupMapping {
- $mapper = new \JsonMapper();
- $payload = json_decode(file_get_contents($file));
- return $mapper->map($payload, new ItemGroupMapping);
- }
+ private function deserialize( $file ): ItemGroupMapping {
+ $mapper = new \JsonMapper();
+ $payload = json_decode( file_get_contents( $file ) );
+ return $mapper->map( $payload, new ItemGroupMapping );
+ }
- public function payloadProvider () : array {
- $toProvide = [];
+ public function payloadProvider(): array {
+ $toProvide = [];
- $path = __DIR__ . '/../data/ItemGroupMapping';
- $files = glob($path . "/*.expected.json");
- foreach ($files as $expectedResultFile) {
- $resultFile = str_replace(".expected", "", $expectedResultFile);
- $toProvide[] = [
- $this->deserialize($resultFile),
- $this->deserialize($expectedResultFile),
- ];
- }
+ $path = __DIR__ . '/../data/ItemGroupMapping';
+ $files = glob( $path . "/*.expected.json" );
+ foreach ( $files as $expectedResultFile ) {
+ $resultFile = str_replace( ".expected", "", $expectedResultFile );
+ $toProvide[] = [
+ $this->deserialize( $resultFile ),
+ $this->deserialize( $expectedResultFile ),
+ ];
+ }
- return $toProvide;
- }
+ return $toProvide;
+ }
}
diff --git a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php
--- a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php
+++ b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php
@@ -2,61 +2,59 @@
namespace Nasqueron\Notifications\Tests\Analyzers;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
-use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
+use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Tests\TestCase;
class JenkinsPayloadAnalyzerConfigurationTest extends TestCase {
- /**
- * Configuration
- *
- * @var \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration
- */
- protected $configuration;
-
- /**
- * Prepares the test
- */
- public function setUp () {
- $filename = __DIR__ . '/../../data/JenkinsPayloadAnalyzer/Nasqueron.json';
- $mapper = new \JsonMapper();
- $this->configuration = $mapper->map(
- json_decode(file_get_contents($filename)),
- new JenkinsPayloadAnalyzerConfiguration('Nasqueron')
- );
-
- parent::setUp();
- }
-
- /**
- * Determines the JSON object is well parsed
- */
- public function testProperties () {
- $this->assertSame("ci", $this->configuration->defaultGroup);
-
- foreach ($this->configuration->map as $item) {
- $this->assertInstanceOf(ItemGroupMapping::class, $item);
- }
- }
-
- ///
- /// Tests for getDefaultGroup
- ///
-
- public function testGetDefaultGroup () {
- $this->configuration->defaultGroup = "quux";
- $this->assertSame("quux", $this->configuration->getDefaultGroup());
- }
-
- public function testGetDefaultGroupWhenNotInConfig () {
- $this->configuration->defaultGroup = "";
- $this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
-
- $this->configuration->defaultGroup = null;
- $this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
- }
+ /**
+ * Configuration
+ *
+ * @var \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration
+ */
+ protected $configuration;
+
+ /**
+ * Prepares the test
+ */
+ public function setUp(): void {
+ $filename = __DIR__ . '/../../data/JenkinsPayloadAnalyzer/Nasqueron.json';
+ $mapper = new \JsonMapper();
+ $this->configuration = $mapper->map(
+ json_decode( file_get_contents( $filename ) ),
+ new JenkinsPayloadAnalyzerConfiguration( 'Nasqueron' )
+ );
+
+ parent::setUp();
+ }
+
+ /**
+ * Determines the JSON object is well parsed
+ */
+ public function testProperties() {
+ $this->assertSame( "ci", $this->configuration->defaultGroup );
+
+ foreach ( $this->configuration->map as $item ) {
+ $this->assertInstanceOf( ItemGroupMapping::class, $item );
+ }
+ }
+
+ ///
+ /// Tests for getDefaultGroup
+ ///
+
+ public function testGetDefaultGroup() {
+ $this->configuration->defaultGroup = "quux";
+ $this->assertSame( "quux", $this->configuration->getDefaultGroup() );
+ }
+
+ public function testGetDefaultGroupWhenNotInConfig() {
+ $this->configuration->defaultGroup = "";
+ $this->assertSame( "nasqueron", $this->configuration->getDefaultGroup() );
+
+ $this->configuration->defaultGroup = null;
+ $this->assertSame( "nasqueron", $this->configuration->getDefaultGroup() );
+ }
}
diff --git a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php
--- a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php
+++ b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php
@@ -3,76 +3,75 @@
namespace Nasqueron\Notifications\Tests\Analyzers;
use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer;
-use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Tests\TestCase;
class JenkinsPayloadAnalyzerTest extends TestCase {
- /**
- * Jenkins analyzer to a successful build
- *
- * @var \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
- */
- protected $analyzer;
+ /**
+ * Jenkins analyzer to a successful build
+ *
+ * @var \Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
+ */
+ protected $analyzer;
- /**
- * @var \stdClass
- */
- protected $payload;
+ /**
+ * @var \stdClass
+ */
+ protected $payload;
- /**
- * Prepares the test
- */
- public function setUp () {
- parent::setUp();
+ /**
+ * Prepares the test
+ */
+ public function setUp(): void {
+ parent::setUp();
- $filename = __DIR__ . '/../../data/payloads/JenkinsToIgnorePayload.json';
- $this->payload = json_decode(file_get_contents($filename));
- $this->analyzer = new JenkinsPayloadAnalyzer("Nasqueron", $this->payload);
- }
+ $filename = __DIR__ . '/../../data/payloads/JenkinsToIgnorePayload.json';
+ $this->payload = json_decode( file_get_contents( $filename ) );
+ $this->analyzer = new JenkinsPayloadAnalyzer( "Nasqueron", $this->payload );
+ }
- public function testGetItemName () {
- $this->assertSame("test-prod-env", $this->analyzer->getItemName());
- }
+ public function testGetItemName() {
+ $this->assertSame( "test-prod-env", $this->analyzer->getItemName() );
+ }
- public function testGetGroup () {
- $this->assertSame("ops", $this->analyzer->getGroup());
- }
+ public function testGetGroup() {
+ $this->assertSame( "ops", $this->analyzer->getGroup() );
+ }
- public function testGetGroupWhenWeNeedDefaultFallback () {
- $this->payload->name = "quux";
- $this->assertSame("ci", $this->analyzer->getGroup());
- }
+ public function testGetGroupWhenWeNeedDefaultFallback() {
+ $this->payload->name = "quux";
+ $this->assertSame( "ci", $this->analyzer->getGroup() );
+ }
- public function testShouldNotifyWhenStatusIsUndefined () {
- unset($this->payload->build->status);
- $this->assertFalse($this->analyzer->shouldNotify());
- }
+ public function testShouldNotifyWhenStatusIsUndefined() {
+ unset( $this->payload->build->status );
+ $this->assertFalse( $this->analyzer->shouldNotify() );
+ }
- /**
- * @dataProvider payloadStatusProvider
- */
- public function testShouldNotifyByStatus ($status, $shouldNotify) {
- $this->payload->build->status = $status;
- $this->assertSame($shouldNotify, $this->analyzer->shouldNotify());
- }
+ /**
+ * @dataProvider payloadStatusProvider
+ */
+ public function testShouldNotifyByStatus( string $status, bool $shouldNotify ) {
+ $this->payload->build->status = $status;
+ $this->assertSame( $shouldNotify, $this->analyzer->shouldNotify() );
+ }
- /**
- * Provides data for testShouldNotifyByStatus
- *
- * @return array
- */
- public function payloadStatusProvider () {
- return [
- // Build status to notify
- ["FAILURE", true],
- ["ABORTED", true],
- ["UNSTABLE", true],
+ /**
+ * Provides data for testShouldNotifyByStatus
+ *
+ * @return array
+ */
+ public function payloadStatusProvider() {
+ return [
+ // Build status to notify
+ [ "FAILURE", true ],
+ [ "ABORTED", true ],
+ [ "UNSTABLE", true ],
- // Build status to ignore
- ["SUCCESS", false],
- ["NOT_BUILT", false],
- ];
- }
+ // Build status to ignore
+ [ "SUCCESS", false ],
+ [ "NOT_BUILT", false ],
+ ];
+ }
}
diff --git a/tests/Analyzers/PayloadAnalyzerConfigurationTest.php b/tests/Analyzers/PayloadAnalyzerConfigurationTest.php
--- a/tests/Analyzers/PayloadAnalyzerConfigurationTest.php
+++ b/tests/Analyzers/PayloadAnalyzerConfigurationTest.php
@@ -2,62 +2,60 @@
namespace Nasqueron\Notifications\Tests\Analyzers;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
-use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
+use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Tests\TestCase;
class PayloadAnalyzerConfigurationTest extends TestCase {
- /**
- * Configuration
- *
- * @var \Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration
- */
- protected $configuration;
-
- /**
- * Prepares the test
- */
- public function setUp () {
- $filename = __DIR__ . '/../data/GitHubPayloadAnalyzer/Nasqueron.json';
- $mapper = new \JsonMapper();
- $this->configuration = $mapper->map(
- json_decode(file_get_contents($filename)),
- new PayloadAnalyzerConfiguration('Nasqueron')
- );
-
- parent::setUp();
- }
-
- /**
- * Determines the JSON object is well parsed
- */
- public function testProperties () {
- $this->assertSame("orgz", $this->configuration->administrativeGroup);
- $this->assertSame("nasqueron", $this->configuration->defaultGroup);
-
- foreach ($this->configuration->map as $item) {
- $this->assertInstanceOf(ItemGroupMapping::class, $item);
- }
- }
-
- ///
- /// Tests for getDefaultGroup
- ///
-
- public function testGetDefaultGroup () {
- $this->configuration->defaultGroup = "quux";
- $this->assertSame("quux", $this->configuration->getDefaultGroup());
- }
-
- public function testGetDefaultGroupWhenNotInConfig () {
- $this->configuration->defaultGroup = "";
- $this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
-
- $this->configuration->defaultGroup = null;
- $this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
- }
+ /**
+ * Configuration
+ *
+ * @var \Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration
+ */
+ protected $configuration;
+
+ /**
+ * Prepares the test
+ */
+ public function setUp(): void {
+ $filename = __DIR__ . '/../data/GitHubPayloadAnalyzer/Nasqueron.json';
+ $mapper = new \JsonMapper();
+ $this->configuration = $mapper->map(
+ json_decode( file_get_contents( $filename ) ),
+ new PayloadAnalyzerConfiguration( 'Nasqueron' )
+ );
+
+ parent::setUp();
+ }
+
+ /**
+ * Determines the JSON object is well parsed
+ */
+ public function testProperties() {
+ $this->assertSame( "orgz", $this->configuration->administrativeGroup );
+ $this->assertSame( "nasqueron", $this->configuration->defaultGroup );
+
+ foreach ( $this->configuration->map as $item ) {
+ $this->assertInstanceOf( ItemGroupMapping::class, $item );
+ }
+ }
+
+ ///
+ /// Tests for getDefaultGroup
+ ///
+
+ public function testGetDefaultGroup() {
+ $this->configuration->defaultGroup = "quux";
+ $this->assertSame( "quux", $this->configuration->getDefaultGroup() );
+ }
+
+ public function testGetDefaultGroupWhenNotInConfig() {
+ $this->configuration->defaultGroup = "";
+ $this->assertSame( "nasqueron", $this->configuration->getDefaultGroup() );
+
+ $this->configuration->defaultGroup = null;
+ $this->assertSame( "nasqueron", $this->configuration->getDefaultGroup() );
+ }
}
diff --git a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
--- a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
+++ b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
@@ -7,84 +7,84 @@
class PhabricatorGroupMappingTest extends TestCase {
- use WithConfiguration;
-
- /**
- * @var PhabricatorGroupMapping|]
- */
- private $mappings;
-
- /**
- * @var PhabricatorStory
- */
- private $story;
-
- public function setUp () {
- parent::setUp();
-
- $config = $this->getPhabricatorPayloadAnalyzerConfiguration();
-
- $keys = [
- 'projects',
- 'words',
- 'strongWords',
- ];
-
- $this->mappings = array_combine($keys, $config->map);
-
- $this->story = $this->getStory();
- }
-
- ///
- /// Tests
- ///
-
- public function testDoesProjectBelong () {
- $mapping = $this->mappings['projects'];
- $this->assertFalse(
- $mapping->doesItemBelong("")
- );
-
- $this->assertFalse(
- $mapping->doesItemBelong("Tasacora")
- );
-
- $this->assertTrue(
- $mapping->doesItemBelong("Docker images")
- );
-
- $this->assertFalse(
- $mapping->doesItemBelong("Docker")
- );
-
- $this->assertFalse(
- $mapping->doesItemBelong("Docker images quux")
- );
- }
-
- public function testDoesStoryBelong () {
- $mapping = $this->mappings['words'];
-
- $this->assertFalse(
- $mapping->doesStoryBelong($this->story)
- );
-
- $this->story->text = "Review the cartography elements.";
- $this->assertTrue(
- $mapping->doesStoryBelong($this->story)
- );
- }
-
- /**
- * Test to fix T773
- */
- public function testDoesStoryBelongWhenWordIsInAnotherCase () {
- $mapping = $this->mappings['words'];
-
- $this->story->text = "Review the Cartography elements.";
- $this->assertTrue(
- $mapping->doesStoryBelong($this->story)
- );
- }
+ use WithConfiguration;
+
+ /**
+ * @var PhabricatorGroupMapping|]
+ */
+ private $mappings;
+
+ /**
+ * @var PhabricatorStory
+ */
+ private $story;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $config = $this->getPhabricatorPayloadAnalyzerConfiguration();
+
+ $keys = [
+ 'projects',
+ 'words',
+ 'strongWords',
+ ];
+
+ $this->mappings = array_combine( $keys, $config->map );
+
+ $this->story = $this->getStory();
+ }
+
+ ///
+ /// Tests
+ ///
+
+ public function testDoesProjectBelong() {
+ $mapping = $this->mappings['projects'];
+ $this->assertFalse(
+ $mapping->doesItemBelong( "" )
+ );
+
+ $this->assertFalse(
+ $mapping->doesItemBelong( "Tasacora" )
+ );
+
+ $this->assertTrue(
+ $mapping->doesItemBelong( "Docker images" )
+ );
+
+ $this->assertFalse(
+ $mapping->doesItemBelong( "Docker" )
+ );
+
+ $this->assertFalse(
+ $mapping->doesItemBelong( "Docker images quux" )
+ );
+ }
+
+ public function testDoesStoryBelong() {
+ $mapping = $this->mappings['words'];
+
+ $this->assertFalse(
+ $mapping->doesStoryBelong( $this->story )
+ );
+
+ $this->story->text = "Review the cartography elements.";
+ $this->assertTrue(
+ $mapping->doesStoryBelong( $this->story )
+ );
+ }
+
+ /**
+ * Test to fix T773
+ */
+ public function testDoesStoryBelongWhenWordIsInAnotherCase() {
+ $mapping = $this->mappings['words'];
+
+ $this->story->text = "Review the Cartography elements.";
+ $this->assertTrue(
+ $mapping->doesStoryBelong( $this->story )
+ );
+ }
}
diff --git a/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php b/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php
--- a/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php
+++ b/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php
@@ -7,90 +7,88 @@
class PhabricatorPayloadAnalyzerTest extends TestCase {
- use WithConfiguration;
-
- /**
- * @var PhabricatorPayloadAnalyzer
- */
- private $analyzer;
-
- /**
- * @var PhabricatorStory
- */
- private $story;
-
- public function setUp () {
- parent::setUp();
-
- $this->story = $this->getStory();
- $this->analyzer = new PhabricatorPayloadAnalyzer(
- "Nasqueron",
- $this->story
- );
- }
-
- public function testGetConfigurationFileName () {
- $this->assertSame(
- "PhabricatorPayloadAnalyzer/Nasqueron.json",
- $this->analyzer->getConfigurationFileName()
- );
- }
-
- public function testGetGroupWhereEventIsAdministrative () {
- $this->markTestIncomplete(
- "Not yet implemented feature. See T664."
- );
-
- $this->assertSame(
- "orgz",
- $this->analyzer->getGroup()
- );
- }
-
- public function testGetGroupWhereStoryDoesntMatchAnything () {
- $this->attachProjectsToStoryMock($this->story, []);
- $this->assertSame(
- "nasqueron",
- $this->analyzer->getGroup()
- );
- }
-
- public function testGetGroupWhereStoryMatchesProject () {
- $this->attachProjectsToStoryMock($this->story, ['Docker images']);
- $this->assertSame(
- "docker",
- $this->analyzer->getGroup()
- );
- }
-
- public function testGetGroupWhereStoryMatchesWords () {
- $this->attachProjectsToStoryMock($this->story, []);
- $this->story->text = "Review the cartography elements.";
- $this->assertSame(
- "tasacora",
- $this->analyzer->getGroup()
- );
- }
-
- public function testGetGroupWhereWordsAreStrong () {
- $this->markTestIncomplete(
- "Not yet implemented feature. See T748."
- );
-
- $this->attachProjectsToStoryMock($this->story, ['Docker images']);
- $this->story->text = "Review the cartography elements on Dwellers.";
-
- $this->assertSame(
- "ops",
- $this->analyzer->getGroup()
- );
- }
-
- /**
- * @expectedException \BadMethodCallException
- */
- public function testGetItemThrowsBadMethodCallException () {
- $this->analyzer->getItemName();
- }
+ use WithConfiguration;
+
+ /**
+ * @var PhabricatorPayloadAnalyzer
+ */
+ private $analyzer;
+
+ /**
+ * @var PhabricatorStory
+ */
+ private $story;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->story = $this->getStory();
+ $this->analyzer = new PhabricatorPayloadAnalyzer(
+ "Nasqueron",
+ $this->story
+ );
+ }
+
+ public function testGetConfigurationFileName() {
+ $this->assertSame(
+ "PhabricatorPayloadAnalyzer/Nasqueron.json",
+ $this->analyzer->getConfigurationFileName()
+ );
+ }
+
+ public function testGetGroupWhereEventIsAdministrative() {
+ $this->markTestIncomplete(
+ "Not yet implemented feature. See T664."
+ );
+
+ $this->assertSame(
+ "orgz",
+ $this->analyzer->getGroup()
+ );
+ }
+
+ public function testGetGroupWhereStoryDoesntMatchAnything() {
+ $this->attachProjectsToStoryMock( $this->story, [] );
+ $this->assertSame(
+ "nasqueron",
+ $this->analyzer->getGroup()
+ );
+ }
+
+ public function testGetGroupWhereStoryMatchesProject() {
+ $this->attachProjectsToStoryMock( $this->story, [ 'Docker images' ] );
+ $this->assertSame(
+ "docker",
+ $this->analyzer->getGroup()
+ );
+ }
+
+ public function testGetGroupWhereStoryMatchesWords() {
+ $this->attachProjectsToStoryMock( $this->story, [] );
+ $this->story->text = "Review the cartography elements.";
+ $this->assertSame(
+ "tasacora",
+ $this->analyzer->getGroup()
+ );
+ }
+
+ public function testGetGroupWhereWordsAreStrong() {
+ $this->markTestIncomplete(
+ "Not yet implemented feature. See T748."
+ );
+
+ $this->attachProjectsToStoryMock( $this->story, [ 'Docker images' ] );
+ $this->story->text = "Review the cartography elements on Dwellers.";
+
+ $this->assertSame(
+ "ops",
+ $this->analyzer->getGroup()
+ );
+ }
+
+ public function testGetItemThrowsBadMethodCallException() {
+ $this->expectException( \BadMethodCallException::class );
+ $this->analyzer->getItemName();
+ }
}
diff --git a/tests/Analyzers/Phabricator/WithConfiguration.php b/tests/Analyzers/Phabricator/WithConfiguration.php
--- a/tests/Analyzers/Phabricator/WithConfiguration.php
+++ b/tests/Analyzers/Phabricator/WithConfiguration.php
@@ -3,34 +3,33 @@
namespace Nasqueron\Notifications\Tests\Analyzers\Phabricator;
use Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorPayloadAnalyzerConfiguration;
-use Nasqueron\Notifications\Phabricator\PhabricatorStory;
/**
* Helper methods to construct needed objects
*/
trait WithConfiguration {
- private function getPhabricatorPayloadAnalyzerConfiguration () {
- $filename = __DIR__ . '/../../data/PhabricatorPayloadAnalyzer/Nasqueron.json';
- $mapper = new \JsonMapper();
- return $mapper->map(
- json_decode(file_get_contents($filename)),
- new PhabricatorPayloadAnalyzerConfiguration('Nasqueron')
- );
- }
+ private function getPhabricatorPayloadAnalyzerConfiguration() {
+ $filename = __DIR__ . '/../../data/PhabricatorPayloadAnalyzer/Nasqueron.json';
+ $mapper = new \JsonMapper();
+ return $mapper->map(
+ json_decode( file_get_contents( $filename ) ),
+ new PhabricatorPayloadAnalyzerConfiguration( 'Nasqueron' )
+ );
+ }
- private function getStory() {
- return $this
- ->getMockBuilder("Nasqueron\Notifications\Phabricator\PhabricatorStory")
- ->setConstructorArgs(["Acme"])
- ->getMock();
- }
+ private function getStory() {
+ return $this
+ ->getMockBuilder( "Nasqueron\Notifications\Phabricator\PhabricatorStory" )
+ ->setConstructorArgs( [ "Acme" ] )
+ ->getMock();
+ }
- private function attachProjectsToStoryMock ($mock, $projects) {
- $mock
- ->expects($this->any())
- ->method("getProjects")
- ->will($this->returnValue($projects));
- }
+ private function attachProjectsToStoryMock( $mock, $projects ) {
+ $mock
+ ->expects( $this->any() )
+ ->method( "getProjects" )
+ ->will( $this->returnValue( $projects ) );
+ }
}
diff --git a/tests/Config/FeaturesTest.php b/tests/Config/FeaturesTest.php
--- a/tests/Config/FeaturesTest.php
+++ b/tests/Config/FeaturesTest.php
@@ -7,24 +7,24 @@
class FeaturesTest extends TestCase {
- public function testEnable () {
- // Find it (en vain …)
- $this->assertNotContains('Quux', Features::getEnabled());
- $this->assertFalse(Features::isEnabled('Quux'));
-
- // Enable it
- Features::enable('Quux');
- $this->assertTrue(Features::isEnabled('Quux'));
- $this->assertContains('Quux', Features::getEnabled());
-
- // Disable it
- Features::disable('Quux');
- $this->assertFalse(Features::isEnabled('Quux'));
-
- // Count it
- $this->assertContains('Quux', Features::getAll());
- $this->assertContains('Quux', Features::getAvailable());
- $this->assertNotContains('Quux', Features::getEnabled());
- }
+ public function testEnable() {
+ // Find it (en vain …)
+ $this->assertNotContains( 'Quux', Features::getEnabled() );
+ $this->assertFalse( Features::isEnabled( 'Quux' ) );
+
+ // Enable it
+ Features::enable( 'Quux' );
+ $this->assertTrue( Features::isEnabled( 'Quux' ) );
+ $this->assertContains( 'Quux', Features::getEnabled() );
+
+ // Disable it
+ Features::disable( 'Quux' );
+ $this->assertFalse( Features::isEnabled( 'Quux' ) );
+
+ // Count it
+ $this->assertContains( 'Quux', Features::getAll() );
+ $this->assertContains( 'Quux', Features::getAvailable() );
+ $this->assertNotContains( 'Quux', Features::getEnabled() );
+ }
}
diff --git a/tests/Config/Reporting/BaseReportEntryTest.php b/tests/Config/Reporting/BaseReportEntryTest.php
--- a/tests/Config/Reporting/BaseReportEntryTest.php
+++ b/tests/Config/Reporting/BaseReportEntryTest.php
@@ -7,20 +7,20 @@
class BaseReportEntryTest extends TestCase {
- public function testFancyString() {
- $this->assertSame('ø', BaseReportEntry::fancyString('', 'ø'));
- $this->assertSame('ø', BaseReportEntry::fancyString('ø', 'ø'));
- $this->assertSame('o', BaseReportEntry::fancyString('o', 'ø'));
- $this->assertSame('', BaseReportEntry::fancyString('', ''));
- }
+ public function testFancyString() {
+ $this->assertSame( 'ø', BaseReportEntry::fancyString( '', 'ø' ) );
+ $this->assertSame( 'ø', BaseReportEntry::fancyString( 'ø', 'ø' ) );
+ $this->assertSame( 'o', BaseReportEntry::fancyString( 'o', 'ø' ) );
+ $this->assertSame( '', BaseReportEntry::fancyString( '', '' ) );
+ }
- public function testFancyBool() {
- $this->assertSame('ø', BaseReportEntry::fancyBool(false, '✓', 'ø'));
- $this->assertSame('✓', BaseReportEntry::fancyBool(true, '✓', 'ø'));
- $this->assertSame('', BaseReportEntry::fancyBool(false, '✓'));
- $this->assertSame('✓', BaseReportEntry::fancyBool(true, '✓'));
- $this->assertSame('', BaseReportEntry::fancyBool(true, '', ''));
- $this->assertSame('', BaseReportEntry::fancyBool(false, '', ''));
- }
+ public function testFancyBool() {
+ $this->assertSame( 'ø', BaseReportEntry::fancyBool( false, '✓', 'ø' ) );
+ $this->assertSame( '✓', BaseReportEntry::fancyBool( true, '✓', 'ø' ) );
+ $this->assertSame( '', BaseReportEntry::fancyBool( false, '✓' ) );
+ $this->assertSame( '✓', BaseReportEntry::fancyBool( true, '✓' ) );
+ $this->assertSame( '', BaseReportEntry::fancyBool( true, '', '' ) );
+ $this->assertSame( '', BaseReportEntry::fancyBool( false, '', '' ) );
+ }
}
diff --git a/tests/Config/Reporting/FeatureReportEntryTest.php b/tests/Config/Reporting/FeatureReportEntryTest.php
--- a/tests/Config/Reporting/FeatureReportEntryTest.php
+++ b/tests/Config/Reporting/FeatureReportEntryTest.php
@@ -7,42 +7,42 @@
class FeatureReportEntryTest extends TestCase {
- /**
- * @var FeatureReportEntry
- */
- private $enabledFeatureEntry;
-
- /**
- * @var FeatureReportEntry
- */
- private $disabledFeatureEntry;
-
- public function setUp () {
- $this->enabledFeatureEntry = new FeatureReportEntry("foo", true);
- $this->disabledFeatureEntry = new FeatureReportEntry("bar", false);
- }
-
- public function testToArray() {
- $this->assertSame(
- ["foo", (string)true],
- $this->enabledFeatureEntry->toArray()
-
- );
- $this->assertSame(
- ["bar", (string)false],
- $this->disabledFeatureEntry->toArray()
- );
- }
-
- public function testToFancyArray() {
- $this->assertSame(
- ["foo", "✓"],
- $this->enabledFeatureEntry->toFancyArray()
- );
- $this->assertSame(
- ["bar", ""],
- $this->disabledFeatureEntry->toFancyArray()
- );
- }
+ /**
+ * @var FeatureReportEntry
+ */
+ private $enabledFeatureEntry;
+
+ /**
+ * @var FeatureReportEntry
+ */
+ private $disabledFeatureEntry;
+
+ public function setUp(): void {
+ $this->enabledFeatureEntry = new FeatureReportEntry( "foo", true );
+ $this->disabledFeatureEntry = new FeatureReportEntry( "bar", false );
+ }
+
+ public function testToArray() {
+ $this->assertSame(
+ [ "foo", (string)true ],
+ $this->enabledFeatureEntry->toArray()
+
+ );
+ $this->assertSame(
+ [ "bar", (string)false ],
+ $this->disabledFeatureEntry->toArray()
+ );
+ }
+
+ public function testToFancyArray() {
+ $this->assertSame(
+ [ "foo", "✓" ],
+ $this->enabledFeatureEntry->toFancyArray()
+ );
+ $this->assertSame(
+ [ "bar", "" ],
+ $this->disabledFeatureEntry->toFancyArray()
+ );
+ }
}
diff --git a/tests/Config/Reporting/IntegrationTest.php b/tests/Config/Reporting/IntegrationTest.php
--- a/tests/Config/Reporting/IntegrationTest.php
+++ b/tests/Config/Reporting/IntegrationTest.php
@@ -6,27 +6,27 @@
class IntegrationTest extends TestCase {
- public function setUp () {
- parent::setUp();
-
- $this->mockServices()
- ->shouldReceive('get')
- ->once()
- ->andReturn([]); // No service
- }
-
- /**
- * Config works.
- */
- public function testConfig() {
- $json = $this->get('/config')
- ->response
- ->getContent();
-
- $this->assertJsonStringEqualsJsonFile(
- __DIR__ . "/../../data/config.json",
- $json
- );
- }
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->mockServices()
+ ->shouldReceive( 'get' )
+ ->once()
+ ->andReturn( [] ); // No service
+ }
+
+ /**
+ * Config works.
+ */
+ public function testConfig() {
+ $json = $this->get( '/config' )
+ ->response
+ ->getContent();
+
+ $this->assertJsonStringEqualsJsonFile(
+ __DIR__ . "/../../data/config.json",
+ $json
+ );
+ }
}
diff --git a/tests/Config/Reporting/ServiceReportEntryTest.php b/tests/Config/Reporting/ServiceReportEntryTest.php
--- a/tests/Config/Reporting/ServiceReportEntryTest.php
+++ b/tests/Config/Reporting/ServiceReportEntryTest.php
@@ -3,33 +3,32 @@
namespace Nasqueron\Notifications\Tests\Config\Reporting;
use Nasqueron\Notifications\Config\Reporting\ServiceReportEntry;
-use Nasqueron\Notifications\Config\Services\Service;
use Nasqueron\Notifications\Tests\TestCase;
class ServiceReportEntryTest extends TestCase {
- /**
- * @var ServiceReportEntry
- */
- private $serviceEntry;
-
- public function setUp () {
- $service = $this->mockService();
- $this->serviceEntry = new ServiceReportEntry($service);
- }
-
- public function testToArray() {
- $this->assertSame(
- ["Storm", "Acme", "http://www.perdu.com", ""],
- $this->serviceEntry->toArray()
- );
- }
-
- public function testToFancyArray() {
- $this->assertSame(
- ["Storm", "Acme", "http://www.perdu.com", "✓"],
- $this->serviceEntry->toFancyArray()
- );
- }
+ /**
+ * @var ServiceReportEntry
+ */
+ private $serviceEntry;
+
+ public function setUp(): void {
+ $service = $this->mockService();
+ $this->serviceEntry = new ServiceReportEntry( $service );
+ }
+
+ public function testToArray() {
+ $this->assertSame(
+ [ "Storm", "Acme", "http://www.perdu.com", "" ],
+ $this->serviceEntry->toArray()
+ );
+ }
+
+ public function testToFancyArray() {
+ $this->assertSame(
+ [ "Storm", "Acme", "http://www.perdu.com", "✓" ],
+ $this->serviceEntry->toFancyArray()
+ );
+ }
}
diff --git a/tests/Config/Services/ServiceTest.php b/tests/Config/Services/ServiceTest.php
--- a/tests/Config/Services/ServiceTest.php
+++ b/tests/Config/Services/ServiceTest.php
@@ -7,39 +7,39 @@
class ServiceTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Config\Services\Service
- */
- private $serviceWithInstance;
-
- /**
- * @var \Nasqueron\Notifications\Config\Services\Service
- */
- private $serviceWithoutInstance;
-
- public function setUp () {
- $this->serviceWithoutInstance = new Service();
-
- $this->serviceWithInstance = clone $this->serviceWithoutInstance;
- $this->serviceWithInstance->instance = "http://www.perdu.com";
- }
-
- ///
- /// Tests for getInstanceName()
- ///
-
- public function testGetInstanceName () {
- $this->assertSame(
- "http://www.perdu.com",
- $this->serviceWithInstance->getInstanceName()
- );
- }
-
- public function testGetInstanceNameWhenThereIsNoInstance () {
- $this->assertSame(
- "ø",
- $this->serviceWithoutInstance->getInstanceName()
- );
- }
+ /**
+ * @var \Nasqueron\Notifications\Config\Services\Service
+ */
+ private $serviceWithInstance;
+
+ /**
+ * @var \Nasqueron\Notifications\Config\Services\Service
+ */
+ private $serviceWithoutInstance;
+
+ public function setUp(): void {
+ $this->serviceWithoutInstance = new Service();
+
+ $this->serviceWithInstance = clone $this->serviceWithoutInstance;
+ $this->serviceWithInstance->instance = "http://www.perdu.com";
+ }
+
+ ///
+ /// Tests for getInstanceName()
+ ///
+
+ public function testGetInstanceName() {
+ $this->assertSame(
+ "http://www.perdu.com",
+ $this->serviceWithInstance->getInstanceName()
+ );
+ }
+
+ public function testGetInstanceNameWhenThereIsNoInstance() {
+ $this->assertSame(
+ "ø",
+ $this->serviceWithoutInstance->getInstanceName()
+ );
+ }
}
diff --git a/tests/Config/Services/ServicesTest.php b/tests/Config/Services/ServicesTest.php
--- a/tests/Config/Services/ServicesTest.php
+++ b/tests/Config/Services/ServicesTest.php
@@ -7,84 +7,84 @@
class ServicesTest extends TestCase {
- private $services;
-
- public function setUp () {
- parent::setUp();
-
- $this->services = Services::loadFromJson('credentials.json');
- }
-
- public function testGet () {
- $actualServices = $this->services->get();
-
- $this->assertGreaterThan(0, $actualServices);
-
- $this->assertSame(
- $this->services->services, // This is public, so testable
- $actualServices
- );
-
- foreach ($actualServices as $service) {
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Config\Services\Service',
- $service
- );
- }
- }
-
- public function testGetForGate () {
- $actualServices = $this->services->getForGate('GitHub');
- $this->assertGreaterThan(0, $actualServices);
- foreach ($actualServices as $service) {
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Config\Services\Service',
- $service
- );
- $this->assertSame('GitHub', $service->gate);
- }
- }
-
- public function testFindServiceByDoor () {
- // Search gives a result
-
- $service = $this->services->findServiceByDoor('GitHub', 'Acme');
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Config\Services\Service',
- $service
- );
- $this->assertSame('GitHub', $service->gate);
- $this->assertSame('Acme', $service->door);
-
- // Search doesn't give any result
-
- $service = $this->services->findServiceByDoor('GitHub', 'Quux');
- $this->assertNull($service);
- }
-
- public function testFindServiceByProperty () {
- // Search gives a result
-
- $service = $this->services->findServiceByProperty(
- 'Phabricator',
- 'instance',
- 'https://phabricator.acme.tld'
- );
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Config\Services\Service',
- $service
- );
- $this->assertSame('Phabricator', $service->gate);
- $this->assertSame('Acme', $service->door);
-
- // Search doesn't give any result
-
- $service = $this->services->findServiceByProperty(
- 'Phabricator',
- 'instance',
- 'https://notfound.acme.tld'
- );
- $this->assertNull($service);
- }
+ private $services;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->services = Services::loadFromJson( 'credentials.json' );
+ }
+
+ public function testGet() {
+ $actualServices = $this->services->get();
+
+ $this->assertGreaterThan( 0, $actualServices );
+
+ $this->assertSame(
+ $this->services->services, // This is public, so testable
+ $actualServices
+ );
+
+ foreach ( $actualServices as $service ) {
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Config\Services\Service',
+ $service
+ );
+ }
+ }
+
+ public function testGetForGate() {
+ $actualServices = $this->services->getForGate( 'GitHub' );
+ $this->assertGreaterThan( 0, $actualServices );
+ foreach ( $actualServices as $service ) {
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Config\Services\Service',
+ $service
+ );
+ $this->assertSame( 'GitHub', $service->gate );
+ }
+ }
+
+ public function testFindServiceByDoor() {
+ // Search gives a result
+
+ $service = $this->services->findServiceByDoor( 'GitHub', 'Acme' );
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Config\Services\Service',
+ $service
+ );
+ $this->assertSame( 'GitHub', $service->gate );
+ $this->assertSame( 'Acme', $service->door );
+
+ // Search doesn't give any result
+
+ $service = $this->services->findServiceByDoor( 'GitHub', 'Quux' );
+ $this->assertNull( $service );
+ }
+
+ public function testFindServiceByProperty() {
+ // Search gives a result
+
+ $service = $this->services->findServiceByProperty(
+ 'Phabricator',
+ 'instance',
+ 'https://phabricator.acme.tld'
+ );
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Config\Services\Service',
+ $service
+ );
+ $this->assertSame( 'Phabricator', $service->gate );
+ $this->assertSame( 'Acme', $service->door );
+
+ // Search doesn't give any result
+
+ $service = $this->services->findServiceByProperty(
+ 'Phabricator',
+ 'instance',
+ 'https://notfound.acme.tld'
+ );
+ $this->assertNull( $service );
+ }
}
diff --git a/tests/Console/Commands/ConfigShowTest.php b/tests/Console/Commands/ConfigShowTest.php
--- a/tests/Console/Commands/ConfigShowTest.php
+++ b/tests/Console/Commands/ConfigShowTest.php
@@ -2,104 +2,102 @@
namespace Nasqueron\Notifications\Tests\Console\Commands;
-use Nasqueron\Notifications\Config\Features;
-use Nasqueron\Notifications\Config\Services\Service;
-
use Mockery;
+use Nasqueron\Notifications\Config\Features;
class ConfigShowTest extends TestCase {
- /**
- * @var string
- */
- protected $class = 'Nasqueron\Notifications\Console\Commands\ConfigShow';
-
- /**
- * Nasqueron\Notifications\Config\Services\Services
- */
- private $servicesMock;
-
- public function setUp () {
- parent::setUp();
-
- $this->servicesMock = $this->mockServices();
- }
-
- public function testRegularExecute () {
- //Our command calls Services::get()
- $this->servicesMock->shouldReceive('get')->once()->andReturn([]);
-
- $this->tester->execute(['command' => $this->command->getName()]);
-
- $this->assertRegexpInDisplay('/Gates/');
- $this->assertRegexpInDisplay('/Features/');
- $this->assertRegexpInDisplay('/Services declared/');
- }
-
- public function testRegularExecuteWithService () {
- $service = $this->mockService();
- $this->servicesMock
- ->shouldReceive('get')
- ->once()
- ->andReturn([$service]);
-
- $this->tester->execute(['command' => $this->command->getName()]);
- $this->assertRegexpInDisplay('/Storm/');
- }
-
- public function testRegularExecuteWithPhabricatorService () {
- $this->mockPhabricatorAPIForProjectsMap();
-
- $service = $this->mockService('Phabricator');
- $this->servicesMock
- ->shouldReceive('get')
- ->once()
- ->andReturn([$service]);
-
- $this->servicesMock
- ->shouldReceive('findServiceByProperty');
-
- $this->tester->execute(['command' => $this->command->getName()]);
- $this->assertRegexpInDisplay(
- '/Phabricator.*Projects map not cached./'
- );
- }
-
- protected function mockProjectsMap () {
- $mock = Mockery::mock(
- 'Nasqueron\Notifications\Phabricator\ProjectsMap'
- );
- $this->app->instance('phabricator-projectsmap', $mock);
-
- return $mock;
- }
-
- public function testRegularExecuteWithPhabricatorServiceWhenTheProjectsMapIsCached () {
- // The services list will return only one, for the Phabricator gate.
- $service = $this->mockService('Phabricator');
- $this->servicesMock
- ->shouldReceive('get')->once()->andReturn([$service]);
-
- // The project map (built by the factory) will say it's cached.
- $this->mockProjectsMap()
- ->shouldReceive('fetch->isCached')->once()->andReturn(true);
-
- $this->tester->execute(['command' => $this->command->getName()]);
- $this->assertRegexpInDisplay('/Phabricator.*✓/');
- }
-
- public function testExecuteWhenSomeFeatureIsDisabled () {
- Features::disable('ActionsReport');
-
- $this->servicesMock->shouldReceive('get')->once()->andReturn([]);
-
- $this->tester->execute(['command' => $this->command->getName()]);
- $this->assertRegexpInDisplay(
- '/Gate *\| *✓ *\|/'
- );
- $this->assertRegexpInDisplay(
- '/ActionsReport *\| *\|/'
- );
- }
+ /**
+ * @var string
+ */
+ protected $class = 'Nasqueron\Notifications\Console\Commands\ConfigShow';
+
+ /**
+ * Nasqueron\Notifications\Config\Services\Services
+ */
+ private $servicesMock;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->servicesMock = $this->mockServices();
+ }
+
+ public function testRegularExecute() {
+ // Our command calls Services::get()
+ $this->servicesMock->shouldReceive( 'get' )->once()->andReturn( [] );
+
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+
+ $this->assertRegexpInDisplay( '/Gates/' );
+ $this->assertRegexpInDisplay( '/Features/' );
+ $this->assertRegexpInDisplay( '/Services declared/' );
+ }
+
+ public function testRegularExecuteWithService() {
+ $service = $this->mockService();
+ $this->servicesMock
+ ->shouldReceive( 'get' )
+ ->once()
+ ->andReturn( [ $service ] );
+
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+ $this->assertRegexpInDisplay( '/Storm/' );
+ }
+
+ public function testRegularExecuteWithPhabricatorService() {
+ $this->mockPhabricatorAPIForProjectsMap();
+
+ $service = $this->mockService( 'Phabricator' );
+ $this->servicesMock
+ ->shouldReceive( 'get' )
+ ->once()
+ ->andReturn( [ $service ] );
+
+ $this->servicesMock
+ ->shouldReceive( 'findServiceByProperty' );
+
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+ $this->assertRegexpInDisplay(
+ '/Phabricator.*Projects map not cached./'
+ );
+ }
+
+ protected function mockProjectsMap() {
+ $mock = Mockery::mock(
+ 'Nasqueron\Notifications\Phabricator\ProjectsMap'
+ );
+ $this->app->instance( 'phabricator-projectsmap', $mock );
+
+ return $mock;
+ }
+
+ public function testRegularExecuteWithPhabricatorServiceWhenTheProjectsMapIsCached() {
+ // The services list will return only one, for the Phabricator gate.
+ $service = $this->mockService( 'Phabricator' );
+ $this->servicesMock
+ ->shouldReceive( 'get' )->once()->andReturn( [ $service ] );
+
+ // The project map (built by the factory) will say it's cached.
+ $this->mockProjectsMap()
+ ->shouldReceive( 'fetch->isCached' )->once()->andReturn( true );
+
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+ $this->assertRegexpInDisplay( '/Phabricator.*✓/' );
+ }
+
+ public function testExecuteWhenSomeFeatureIsDisabled() {
+ Features::disable( 'ActionsReport' );
+
+ $this->servicesMock->shouldReceive( 'get' )->once()->andReturn( [] );
+
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+ $this->assertRegexpInDisplay(
+ '/Gate *\| *✓ *\|/'
+ );
+ $this->assertRegexpInDisplay(
+ '/ActionsReport *\| *\|/'
+ );
+ }
}
diff --git a/tests/Console/Commands/ConfigValidateTest.php b/tests/Console/Commands/ConfigValidateTest.php
--- a/tests/Console/Commands/ConfigValidateTest.php
+++ b/tests/Console/Commands/ConfigValidateTest.php
@@ -6,55 +6,55 @@
class ConfigValidateTest extends TestCase {
- /**
- * @var string
- */
- protected $class = 'Nasqueron\Notifications\Console\Commands\ConfigValidate';
-
- const TEST_FILE = 'bug.json';
-
- public function testRegularExecute () {
- $this->tester->execute(['command' => $this->command->getName()]);
-
- // When all files are valid, nothing is displayed
- $this->assertEquals('', $this->tester->getDisplay());
- }
-
- /**
- * @dataProvider provideErrors
- */
- public function testSyntaxErrorExecute (string $content, string $error) {
- $this->populateTestFile($content); // Not JSON
-
- $this->tester->execute(['command' => $this->command->getName()]);
-
- // When all files are valid, nothing is displayed
- $this->assertRegexpInDisplay("/$error/");
- }
-
- /**
- * Provides invalid JSON strings and associated error
- */
- public function provideErrors () : array {
- return [
- ["lorem ipsum dolor", "Syntax error"],
- ['{"}', "Control character error"]
- ];
- }
-
- private function populateTestFile (string $content) : void {
- Storage::disk('local')->put(self::TEST_FILE, $content);
- }
-
- private function deleteTestFile () : void {
- $fs = Storage::disk('local');
- if ($fs->exists(self::TEST_FILE)) {
- $fs->delete(self::TEST_FILE);
- }
- }
-
- public function tearDown () {
- $this->deleteTestFile();
- parent::tearDown();
- }
+ /**
+ * @var string
+ */
+ protected $class = 'Nasqueron\Notifications\Console\Commands\ConfigValidate';
+
+ const TEST_FILE = 'bug.json';
+
+ public function testRegularExecute() {
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+
+ // When all files are valid, nothing is displayed
+ $this->assertSame( '', $this->tester->getDisplay() );
+ }
+
+ /**
+ * @dataProvider provideErrors
+ */
+ public function testSyntaxErrorExecute( string $content, string $error ) {
+ $this->populateTestFile( $content ); // Not JSON
+
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+
+ // When all files are valid, nothing is displayed
+ $this->assertRegexpInDisplay( "/$error/" );
+ }
+
+ /**
+ * Provides invalid JSON strings and associated error
+ */
+ public function provideErrors(): array {
+ return [
+ [ "lorem ipsum dolor", "Syntax error" ],
+ [ '{"}', "Control character error" ]
+ ];
+ }
+
+ private function populateTestFile( string $content ): void {
+ Storage::disk( 'local' )->put( self::TEST_FILE, $content );
+ }
+
+ private function deleteTestFile(): void {
+ $fs = Storage::disk( 'local' );
+ if ( $fs->exists( self::TEST_FILE ) ) {
+ $fs->delete( self::TEST_FILE );
+ }
+ }
+
+ public function tearDown(): void {
+ $this->deleteTestFile();
+ parent::tearDown();
+ }
}
diff --git a/tests/Console/Commands/InspireTest.php b/tests/Console/Commands/InspireTest.php
--- a/tests/Console/Commands/InspireTest.php
+++ b/tests/Console/Commands/InspireTest.php
@@ -4,15 +4,15 @@
class InspireTest extends TestCase {
- /**
- * @var string
- */
- protected $class = 'Nasqueron\Notifications\Console\Commands\Inspire';
+ /**
+ * @var string
+ */
+ protected $class = 'Nasqueron\Notifications\Console\Commands\Inspire';
- public function testExecute () {
- // A quote contain a - character and is embedded by PHP_EOL
- $this->tester->execute(['command' => $this->command->getName()]);
- $this->assertRegexpInDisplay('/\n.*-.*\n/');
- }
+ public function testExecute() {
+ // A quote contain a - character and is embedded by PHP_EOL
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+ $this->assertRegexpInDisplay( '/\n.*-.*\n/' );
+ }
}
diff --git a/tests/Console/Commands/NotificationsPayloadTest.php b/tests/Console/Commands/NotificationsPayloadTest.php
--- a/tests/Console/Commands/NotificationsPayloadTest.php
+++ b/tests/Console/Commands/NotificationsPayloadTest.php
@@ -6,81 +6,78 @@
class NotificationsPayloadTest extends TestCase {
- /**
- * @var string
- */
- protected $class = NotificationsPayload::class;
+ /**
+ * @var string
+ */
+ protected $class = NotificationsPayload::class;
- public function testRegularExecute () {
- $path = __DIR__ . '/../../data/payloads/DockerHubPushPayload.json';
- $this->tester->execute([
- 'command' => $this->command->getName(),
- 'service' => 'DockerHub',
- 'payload' => $path,
- 'args' => [
- 'Acme',
- 'push'
- ],
- ]);
+ public function testRegularExecute() {
+ $path = __DIR__ . '/../../data/payloads/DockerHubPushPayload.json';
+ $this->tester->execute( [
+ 'command' => $this->command->getName(),
+ 'service' => 'DockerHub',
+ 'payload' => $path,
+ 'args' => [
+ 'Acme',
+ 'push'
+ ],
+ ] );
- $this->assertDisplayContains('"service": "DockerHub"');
- $this->assertDisplayContains('"project": "Acme"');
- $this->assertDisplayContains('svendowideit\/testhook');
- }
+ $this->assertDisplayContains( '"service": "DockerHub"' );
+ $this->assertDisplayContains( '"project": "Acme"' );
+ $this->assertDisplayContains( 'svendowideit\/testhook' );
+ }
- public function testPhabricatorPayload () {
- $path = __DIR__ . '/../../data/payloads/PhabricatorPastePayload.json';
- $this->tester->execute([
- 'command' => $this->command->getName(),
- 'service' => 'Phabricator',
- 'payload' => $path,
- 'args' => [
- 'Acme',
- ],
- ]);
+ public function testPhabricatorPayload() {
+ $path = __DIR__ . '/../../data/payloads/PhabricatorPastePayload.json';
+ $this->tester->execute( [
+ 'command' => $this->command->getName(),
+ 'service' => 'Phabricator',
+ 'payload' => $path,
+ 'args' => [
+ 'Acme',
+ ],
+ ] );
- $this->assertDisplayContains('"service": "Phabricator"');
- $this->assertDisplayContains('"project": "Acme"');
- $this->assertDisplayContains('"type": "PSTE"');
- }
+ $this->assertDisplayContains( '"service": "Phabricator"' );
+ $this->assertDisplayContains( '"project": "Acme"' );
+ $this->assertDisplayContains( '"type": "PSTE"' );
+ }
- /**
- * @expectedException InvalidArgumentException
- */
- public function testArgumentsArrayCombine () {
- NotificationsPayload::argumentsArrayCombine(['foo'], []);
- }
+ public function testArgumentsArrayCombine() {
+ $this->expectException( \InvalidArgumentException::class );
+ NotificationsPayload::argumentsArrayCombine( [ 'foo' ], [] );
+ }
- public function testFileNotFound () {
- $this->tester->execute([
- 'command' => $this->command->getName(),
- 'service' => 'DockerHub',
- 'payload' => "/tmp/not.found",
- 'args' => [
- 'Acme',
- 'push'
- ],
- ]);
+ public function testFileNotFound() {
+ $this->tester->execute( [
+ 'command' => $this->command->getName(),
+ 'service' => 'DockerHub',
+ 'payload' => "/tmp/not.found",
+ 'args' => [
+ 'Acme',
+ 'push'
+ ],
+ ] );
- $this->assertDisplayContains('File not found: /tmp/not.found');
- }
+ $this->assertDisplayContains( 'File not found: /tmp/not.found' );
+ }
- public function testServiceNotFound () {
- $path = __DIR__ . '/../../data/payloads/DockerHubPushPayload.json';
- $this->tester->execute([
- 'command' => $this->command->getName(),
- 'service' => 'InterdimensionalTeleport',
- 'payload' => $path,
- 'args' => [
- 'Acme',
- 'push'
- ],
- ]);
+ public function testServiceNotFound() {
+ $path = __DIR__ . '/../../data/payloads/DockerHubPushPayload.json';
+ $this->tester->execute( [
+ 'command' => $this->command->getName(),
+ 'service' => 'InterdimensionalTeleport',
+ 'payload' => $path,
+ 'args' => [
+ 'Acme',
+ 'push'
+ ],
+ ] );
- $this->assertDisplayContains(
- 'Unknown service: InterdimensionalTeleport'
- );
-
- }
+ $this->assertDisplayContains(
+ 'Unknown service: InterdimensionalTeleport'
+ );
+ }
}
diff --git a/tests/Console/Commands/PhabricatorProjectsMapTest.php b/tests/Console/Commands/PhabricatorProjectsMapTest.php
--- a/tests/Console/Commands/PhabricatorProjectsMapTest.php
+++ b/tests/Console/Commands/PhabricatorProjectsMapTest.php
@@ -2,33 +2,32 @@
namespace Nasqueron\Notifications\Tests\Console\Commands;
-use Nasqueron\Notifications\Config\Services\Service;
use Nasqueron\Notifications\Console\Commands\PhabricatorProjectsMap;
class PhabricatorProjectsMapTest extends TestCase {
- /**
- * @var string
- */
- protected $class = PhabricatorProjectsMap::class;
-
- public function setUp () {
- parent::setUp();
-
- $service = $this->mockService('Phabricator');
- $this->mockServices()
- ->shouldReceive('getForGate')
- ->once()
- ->andReturn([$service]);
-
- $this->mockPhabricatorAPIForProjectsMap();
- }
-
- public function testRegularExecute () {
- $this->tester->execute(['command' => $this->command->getName()]);
- $this->assertRegexpInDisplay('/PHID.*Project name/');
- $this->assertRegexpInDisplay(
- '/PHID-PROJ-cztcgpvqr6smnnekotq7.*Agora/'
- );
- }
+ /**
+ * @var string
+ */
+ protected $class = PhabricatorProjectsMap::class;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $service = $this->mockService( 'Phabricator' );
+ $this->mockServices()
+ ->shouldReceive( 'getForGate' )
+ ->once()
+ ->andReturn( [ $service ] );
+
+ $this->mockPhabricatorAPIForProjectsMap();
+ }
+
+ public function testRegularExecute() {
+ $this->tester->execute( [ 'command' => $this->command->getName() ] );
+ $this->assertRegexpInDisplay( '/PHID.*Project name/' );
+ $this->assertRegexpInDisplay(
+ '/PHID-PROJ-cztcgpvqr6smnnekotq7.*Agora/'
+ );
+ }
}
diff --git a/tests/Console/Commands/TestCase.php b/tests/Console/Commands/TestCase.php
--- a/tests/Console/Commands/TestCase.php
+++ b/tests/Console/Commands/TestCase.php
@@ -2,51 +2,47 @@
namespace Nasqueron\Notifications\Tests\Console\Commands;
-use Nasqueron\Notifications\Config\Services\Service;
-use Nasqueron\Notifications\Tests\TestCase as BaseTestCase;
-
use Illuminate\Contracts\Console\Kernel;
+use Nasqueron\Notifications\Tests\TestCase as BaseTestCase;
use Symfony\Component\Console\Tester\CommandTester;
-use Mockery;
-
class TestCase extends BaseTestCase {
- ///
- /// Commands test environment
- ///
-
- /**
- * @var Symfony\Component\Console\Command
- */
- protected $command;
-
- /**
- * @var Symfony\Component\Console\Tester\CommandTester;
- */
- protected $tester;
-
- public function setUp () {
- parent::setUp();
-
- $kernel = $this->app->make(Kernel::class);
- $this->command = $kernel->getByClass($this->class);
- $this->tester = new CommandTester($this->command);
- }
-
- ///
- /// Display assertions
- ///
-
- public function assertDisplayContains(string $expectedNeedle) {
- $this->assertContains(
- $expectedNeedle,
- $this->tester->getDisplay()
- );
- }
-
- public function assertRegexpInDisplay (string $pattern) {
- $this->assertRegexp($pattern, $this->tester->getDisplay());
- }
+ ///
+ /// Commands test environment
+ ///
+
+ /**
+ * @var Symfony\Component\Console\Command
+ */
+ protected $command;
+
+ /**
+ * @var Symfony\Component\Console\Tester\CommandTester
+ */
+ protected $tester;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $kernel = $this->app->make( Kernel::class );
+ $this->command = $kernel->getByClass( $this->class );
+ $this->tester = new CommandTester( $this->command );
+ }
+
+ ///
+ /// Display assertions
+ ///
+
+ public function assertDisplayContains( string $expectedNeedle ) {
+ $this->assertContains(
+ $expectedNeedle,
+ $this->tester->getDisplay()
+ );
+ }
+
+ public function assertRegexpInDisplay( string $pattern ) {
+ $this->assertRegexp( $pattern, $this->tester->getDisplay() );
+ }
}
diff --git a/tests/Console/KernelTest.php b/tests/Console/KernelTest.php
--- a/tests/Console/KernelTest.php
+++ b/tests/Console/KernelTest.php
@@ -2,124 +2,116 @@
namespace Nasqueron\Notifications\Tests\Console;
-use Nasqueron\Notifications\Tests\TestCase;
-
-use Nasqueron\Notifications\Console\Kernel;
-use Illuminate\Contracts\Console\Kernel as BaseKernel;
-
-use Artisan;
use File;
+use Illuminate\Contracts\Console\Kernel as BaseKernel;
+use Nasqueron\Notifications\Tests\TestCase;
class KernelTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Console\Kernel
- */
- private $kernel;
-
- /**
- * The actual list of services providers
- *
- * @var string[]
- */
- private $commands;
-
- /**
- * The service providers' namespace
- *
- * @var string
- */
- private $namespace;
-
- public function setUp () {
- parent::setUp();
-
- $this->kernel = $this->app->make(BaseKernel::class);
- $this->commands = $this->kernel->all();
- $this->namespace = $this->app->getInstance()->getNamespace()
- . 'Console\\Commands\\';
- }
-
- public function testOmittedFiles () {
- $files = File::allFiles(app_path('Console/Commands'));
-
- foreach ($files as $file) {
- $class = $this->namespace . $file->getBasename('.php');
- $this->assertArrayContainsInstanceOf(
- $class,
- $this->commands,
- "The class $class should be added to app/Console/Kernel.php."
- );
- }
- }
-
- public function testGet () {
- $this->assertInstanceOf(
- \Nasqueron\Notifications\Console\Commands\Inspire::class,
- $this->kernel->get('inspire')
- );
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function testGetWhenCommandDoesNotExist () {
- $this->kernel->get('notexisting');
- }
-
- public function testGetByClass () {
- $class = \Nasqueron\Notifications\Console\Commands\Inspire::class;
- $this->assertInstanceOf($class, $this->kernel->getByClass($class));
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function testGetByClassWhenCommandDoesNotExist () {
- $this->kernel->getByClass('notexisting');
- }
-
- ///
- /// Custom assertions
- ///
-
- /**
- * Asserts the specified array contains an element of an expected type.
- *
- * @param mixed $expectedType The type to find among the array elements
- * @param array $haystack The array where to find
- * @param string $message The test message
- */
- public static function assertArrayContainsInstanceOf (
- $expectedType,
- $haystack,
- $message = ''
- ) {
- self::assertThat(
- self::arrayContainsInstanceOf($expectedType, $haystack),
- self::isTrue(),
- $message
- );
- }
-
- /**
- * Determines if the specified array contains at least one instance of the
- * specified type.
- *
- * @param mixed $expectedType The type to find among the array elements
- * @param array $haystack The array where to find
- * @return bool
- */
- protected static function arrayContainsInstanceOf (
- $expectedType,
- $haystack
- ) {
- foreach ($haystack as $item) {
- if ($item instanceof $expectedType) {
- return true;
- }
- }
-
- return false;
- }
+ /**
+ * @var \Nasqueron\Notifications\Console\Kernel
+ */
+ private $kernel;
+
+ /**
+ * The actual list of services providers
+ *
+ * @var string[]
+ */
+ private $commands;
+
+ /**
+ * The service providers' namespace
+ *
+ * @var string
+ */
+ private $namespace;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->kernel = $this->app->make( BaseKernel::class );
+ $this->commands = $this->kernel->all();
+ $this->namespace = $this->app->getInstance()->getNamespace()
+ . 'Console\\Commands\\';
+ }
+
+ public function testOmittedFiles() {
+ $files = File::allFiles( app_path( 'Console/Commands' ) );
+
+ foreach ( $files as $file ) {
+ $class = $this->namespace . $file->getBasename( '.php' );
+ $this->assertArrayContainsInstanceOf(
+ $class,
+ $this->commands,
+ "The class $class should be added to app/Console/Kernel.php."
+ );
+ }
+ }
+
+ public function testGet() {
+ $this->assertInstanceOf(
+ \Nasqueron\Notifications\Console\Commands\Inspire::class,
+ $this->kernel->get( 'inspire' )
+ );
+ }
+
+ public function testGetWhenCommandDoesNotExist() {
+ $this->expectException( \RuntimeException::class );
+ $this->kernel->get( 'notexisting' );
+ }
+
+ public function testGetByClass() {
+ $class = \Nasqueron\Notifications\Console\Commands\Inspire::class;
+ $this->assertInstanceOf( $class, $this->kernel->getByClass( $class ) );
+ }
+
+ public function testGetByClassWhenCommandDoesNotExist() {
+ $this->expectException( \RuntimeException::class );
+ $this->kernel->getByClass( 'notexisting' );
+ }
+
+ ///
+ /// Custom assertions
+ ///
+
+ /**
+ * Asserts the specified array contains an element of an expected type.
+ *
+ * @param mixed $expectedType The type to find among the array elements
+ * @param array $haystack The array where to find
+ * @param string $message The test message
+ */
+ public static function assertArrayContainsInstanceOf(
+ $expectedType,
+ array $haystack,
+ string $message = ''
+ ) {
+ self::assertThat(
+ self::arrayContainsInstanceOf( $expectedType, $haystack ),
+ self::isTrue(),
+ $message
+ );
+ }
+
+ /**
+ * Determines if the specified array contains at least one instance of the
+ * specified type.
+ *
+ * @param mixed $expectedType The type to find among the array elements
+ * @param array $haystack The array where to find
+ * @return bool
+ */
+ protected static function arrayContainsInstanceOf(
+ $expectedType,
+ array $haystack
+ ) {
+ foreach ( $haystack as $item ) {
+ if ( $item instanceof $expectedType ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
diff --git a/tests/Exceptions/HandlerTest.php b/tests/Exceptions/HandlerTest.php
--- a/tests/Exceptions/HandlerTest.php
+++ b/tests/Exceptions/HandlerTest.php
@@ -2,52 +2,51 @@
namespace Nasqueron\Notifications\Tests\Exceptions;
-use Illuminate\Auth\Access\AuthorizationException;
-use Nasqueron\Notifications\Exceptions\Handler;
-use Nasqueron\Notifications\Tests\TestCase;
-
use App;
use Config;
+use Illuminate\Auth\Access\AuthorizationException;
use Mockery;
+use Nasqueron\Notifications\Exceptions\Handler;
+use Nasqueron\Notifications\Tests\TestCase;
class HandlerTest extends TestCase {
- /**
- * Illuminate\Foundation\Exceptions\Handler
- */
- private $handler;
+ /**
+ * Illuminate\Foundation\Exceptions\Handler
+ */
+ private $handler;
- /**
- * Raven_Client
- */
- private $ravenClientMock;
+ /**
+ * Raven_Client
+ */
+ private $ravenClientMock;
- public function setUp () {
- parent::setUp();
+ public function setUp(): void {
+ parent::setUp();
- $this->handler = new Handler(app());
+ $this->handler = new Handler( app() );
- $this->mockRavenClient();
- }
+ $this->mockRavenClient();
+ }
- protected function mockRavenClient () {
- // Inject into our container a mock of Raven_Client
- $this->ravenClientMock = Mockery::mock('Raven_Client');
- $this->app->instance('raven', $this->ravenClientMock);
+ protected function mockRavenClient() {
+ // Inject into our container a mock of Raven_Client
+ $this->ravenClientMock = Mockery::mock( 'Raven_Client' );
+ $this->app->instance( 'raven', $this->ravenClientMock );
- // Environment shouldn't be 'testing' and DSN should be defined,
- // so Handler::report will call Raven to report to Sentry
- Config::set('app.env', 'testing-raven');
- Config::set('services.sentry.dsn', 'mock');
- }
+ // Environment shouldn't be 'testing' and DSN should be defined,
+ // so Handler::report will call Raven to report to Sentry
+ Config::set( 'app.env', 'testing-raven' );
+ Config::set( 'services.sentry.dsn', 'mock' );
+ }
- public function testRavenReport () {
- $this->ravenClientMock->shouldReceive('captureException')->once();
- $this->handler->report(new \Exception);
- }
+ public function testRavenReport() {
+ $this->ravenClientMock->shouldReceive( 'captureException' )->once();
+ $this->handler->report( new \Exception );
+ }
- public function testExceptionInDontReportArray () {
- $this->ravenClientMock->shouldReceive('captureException')->never();
- $this->handler->report(new AuthorizationException);
- }
+ public function testExceptionInDontReportArray() {
+ $this->ravenClientMock->shouldReceive( 'captureException' )->never();
+ $this->handler->report( new AuthorizationException );
+ }
}
diff --git a/tests/Facades/DockerHubTest.php b/tests/Facades/DockerHubTest.php
--- a/tests/Facades/DockerHubTest.php
+++ b/tests/Facades/DockerHubTest.php
@@ -2,20 +2,17 @@
namespace Nasqueron\Notifications\Tests\Facades;
-use Nasqueron\Notifications\Tests\TestCase;
-
-use Config;
use DockerHub;
-
use Keruald\DockerHub\Build\TriggerBuildFactory;
+use Nasqueron\Notifications\Tests\TestCase;
class DockerHubTest extends TestCase {
- public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
- $this->assertInstanceOf(
- TriggerBuildFactory::class,
- DockerHub::getFacadeRoot()
- );
- }
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer() {
+ $this->assertInstanceOf(
+ TriggerBuildFactory::class,
+ DockerHub::getFacadeRoot()
+ );
+ }
}
diff --git a/tests/Facades/MailgunTest.php b/tests/Facades/MailgunTest.php
--- a/tests/Facades/MailgunTest.php
+++ b/tests/Facades/MailgunTest.php
@@ -2,20 +2,17 @@
namespace Nasqueron\Notifications\Tests\Facades;
-use Nasqueron\Notifications\Tests\TestCase;
-
-use Config;
-use Mailgun;
-
use Keruald\Mailgun\MailgunMessageFactory;
+use Mailgun;
+use Nasqueron\Notifications\Tests\TestCase;
class MailgunTest extends TestCase {
- public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
- $this->assertInstanceOf(
- MailgunMessageFactory::class,
- Mailgun::getFacadeRoot()
- );
- }
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer() {
+ $this->assertInstanceOf(
+ MailgunMessageFactory::class,
+ Mailgun::getFacadeRoot()
+ );
+ }
}
diff --git a/tests/Facades/PhabricatorAPITest.php b/tests/Facades/PhabricatorAPITest.php
--- a/tests/Facades/PhabricatorAPITest.php
+++ b/tests/Facades/PhabricatorAPITest.php
@@ -7,10 +7,10 @@
class PhabricatorAPITest extends TestCase {
- public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory',
- PhabricatorAPI::getFacadeRoot()
- );
- }
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer() {
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory',
+ PhabricatorAPI::getFacadeRoot()
+ );
+ }
}
diff --git a/tests/Facades/ProjectsMapTest.php b/tests/Facades/ProjectsMapTest.php
--- a/tests/Facades/ProjectsMapTest.php
+++ b/tests/Facades/ProjectsMapTest.php
@@ -7,10 +7,10 @@
class ProjectsMapTest extends TestCase {
- public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Phabricator\ProjectsMapFactory',
- ProjectsMap::getFacadeRoot()
- );
- }
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer() {
+ $this->assertInstanceOf(
+ 'Nasqueron\Notifications\Phabricator\ProjectsMapFactory',
+ ProjectsMap::getFacadeRoot()
+ );
+ }
}
diff --git a/tests/Facades/RavenTest.php b/tests/Facades/RavenTest.php
--- a/tests/Facades/RavenTest.php
+++ b/tests/Facades/RavenTest.php
@@ -2,28 +2,27 @@
namespace Nasqueron\Notifications\Tests\Facades;
-use Nasqueron\Notifications\Tests\TestCase;
-
use Config;
+use Nasqueron\Notifications\Tests\TestCase;
use Raven;
class RavenTest extends TestCase {
- public function testIfFacadeAccessorCouldBeResolvedInAppContainer () {
- $this->assertInstanceOf(
- 'Raven_Client',
- Raven::getFacadeRoot()
- );
- }
-
- public function testIsConfigured () {
- Config::set("services.sentry.dsn", "something");
- $this->assertTrue(Raven::isConfigured());
- }
-
- public function testIsConfiguredWhenItIsNot () {
- Config::offsetUnset("services.sentry.dsn");
- $this->assertFalse(Raven::isConfigured());
- }
+ public function testIfFacadeAccessorCouldBeResolvedInAppContainer() {
+ $this->assertInstanceOf(
+ 'Raven_Client',
+ Raven::getFacadeRoot()
+ );
+ }
+
+ public function testIsConfigured() {
+ Config::set( "services.sentry.dsn", "something" );
+ $this->assertTrue( Raven::isConfigured() );
+ }
+
+ public function testIsConfiguredWhenItIsNot() {
+ Config::offsetUnset( "services.sentry.dsn" );
+ $this->assertFalse( Raven::isConfigured() );
+ }
}
diff --git a/tests/Http/Controllers/GitHubGateControllerTest.php b/tests/Http/Controllers/GitHubGateControllerTest.php
--- a/tests/Http/Controllers/GitHubGateControllerTest.php
+++ b/tests/Http/Controllers/GitHubGateControllerTest.php
@@ -5,91 +5,90 @@
use Nasqueron\Notifications\Tests\TestCase;
class GitHubGateControllerTest extends TestCase {
- public function setUp () {
- parent::setUp();
+ public function setUp(): void {
+ parent::setUp();
- $this->disableEvents();
- }
+ $this->disableEvents();
+ }
- /**
- * GitHub gate works.
- *
- * @return void
- */
- public function testGet () {
- $this->visit('/gate/GitHub')
- ->see('POST');
- }
+ /**
+ * GitHub gate works.
+ *
+ * @return void
+ */
+ public function testGet() {
+ $this->sendPayload( '/gate/GitHub', "test" );
+ }
- /**
- * Tests a GitHub gate payload.
- */
- public function testPost () {
- $payload = file_get_contents(__DIR__ . '/../../data/payloads/GitHubPingPayload.json');
- $this->sendPayload(
- '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
- $payload,
- 'POST',
- [
- 'X-Github-Event' => 'ping',
- 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c'
- ]
- )
- ->seeJson([
- 'gate' => 'GitHub',
- 'door' => 'Quux',
- 'actions' => []
- ]);
+ /**
+ * Tests a GitHub gate payload.
+ */
+ public function testPost() {
+ $payload = file_get_contents( __DIR__ . '/../../data/payloads/GitHubPingPayload.json' );
+ $this->sendPayload(
+ '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
+ $payload,
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c'
+ ]
+ )
+ ->seeJson( [
+ 'gate' => 'GitHub',
+ 'door' => 'Quux',
+ 'actions' => []
+ ] );
- $this->assertResponseOk();
- }
+ $this->assertResponseOk();
+ }
- /**
- * Tests a malformed GitHub gate payload.
- */
- public function testMalformedPost () {
- $this->sendPayload(
- '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
- "",
- 'POST',
- [
- 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
- ]
- );
- $this->assertResponseStatus(400);
+ /**
+ * Tests a malformed GitHub gate payload.
+ */
+ public function testMalformedPost() {
+ $this->sendPayload(
+ '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
+ "",
+ 'POST',
+ [
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
+ ]
+ );
+ $this->assertResponseStatus( 400 );
- $this->sendPayload(
- '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
- "",
- 'POST',
- [
- 'X-Github-Event' => 'ping',
- ]
- );
- $this->assertResponseStatus(400);
+ $this->sendPayload(
+ '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
+ "",
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ ]
+ );
+ $this->assertResponseStatus( 400 );
- $this->sendPayload(
- '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
- "",
- 'POST',
- [
- 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
- 'X-Github-Event' => 'ping',
- ]
- );
- $this->assertResponseStatus(400);
- }
+ $this->sendPayload(
+ '/gate/GitHub/Quux', // A gate not existing in data/credentials.json
+ "",
+ 'POST',
+ [
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
+ 'X-Github-Event' => 'ping',
+ ]
+ );
+ $this->assertResponseStatus( 400 );
+ }
- public function testEmptySignature () {
- $this->sendPayload(
- '/gate/GitHub/Acme', // A gate existing in data/credentials.json
- "",
- 'POST',
- [
- 'X-Github-Event' => 'ping',
- 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
- ]
- );
- $this->assertResponseStatus(403);
- }
+ public function testEmptySignature() {
+ $this->sendPayload(
+ '/gate/GitHub/Acme', // A gate existing in data/credentials.json
+ "",
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
+ ]
+ );
+ $this->assertResponseStatus( 403 );
+ }
}
diff --git a/tests/Http/PayloadFullTest.php b/tests/Http/PayloadFullTest.php
--- a/tests/Http/PayloadFullTest.php
+++ b/tests/Http/PayloadFullTest.php
@@ -7,177 +7,177 @@
class PayloadFullTest extends TestCase {
- public function setUp () {
- parent::setUp();
-
- $this->disableBroker();
- }
-
- /**
- * Sends a GitHub ping payload to the application, with a valid signature
- */
- protected function sendValidTestPayload () {
- return $this->sendTestPayload('sha1=25f6cbd17ea4c6c69958b95fb88c879de4b66dcc');
- }
-
- /**
- * Sends a GitHub ping payload to the application, with a valid signature
- */
- protected function sendInvalidTestPayload () {
- return $this->sendTestPayload('sha1=somethingwrong');
- }
-
- protected function sendTestPayload ($signature) {
- $payload = file_get_contents(__DIR__ . '/../data/payloads/GitHubPingPayload.json');
- $this->sendPayload(
- '/gate/GitHub/Acme', // A gate existing in data/credentials.json
- $payload,
- 'POST',
- [
- 'X-Github-Event' => 'ping',
- 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
- 'X-Hub-Signature' => $signature,
- ]
- );
- return $this;
- }
-
- /**
- * Tests a GitHub gate payload.
- */
- public function testPost () {
- $this->sendValidTestPayload()->seeJson([
- 'gate' => 'GitHub',
- 'door' => 'Acme',
- 'action' => 'AMQPAction'
- ]);
-
- $this->assertResponseOk();
- }
-
- /**
- * Tests a DockerHub gate payload.
- */
- public function testDockerHubPayload () {
- $payload = file_get_contents(__DIR__ . '/../data/payloads/DockerHubPushPayload.json');
- $this->sendPayload(
- '/gate/DockerHub/Acme', // A gate existing in data/credentials.json
- $payload,
- 'POST',
- []
- )->seeJson([
- 'gate' => 'DockerHub',
- 'door' => 'Acme',
- 'action' => 'AMQPAction'
- ]);
- $this->assertResponseOk();
- }
-
- /**
- * Tests a Jenkins gate payload.
- */
- public function testJenkinsPayload () {
- $payload = file_get_contents(__DIR__ . '/../data/payloads/JenkinsPayload.json');
-
- $this->sendPayload(
- '/gate/Jenkins/Acme', // A gate existing in data/credentials.json
- $payload,
- 'POST',
- []
- )->seeJson([
- 'gate' => 'Jenkins',
- 'door' => 'Acme',
- 'action' => 'AMQPAction'
- ]);
- $this->assertResponseOk();
- }
-
- private function getDataForPhabricatorPayloadTests () {
- return [
- 'storyID' => 3849,
- 'storyType' => 'PhabricatorApplicationTransactionFeedStory',
- 'storyData[objectPHID]' => 'PHID-TASK-l34fw5wievp6n6rnvpuk',
- 'storyData[transactionPHIDs][PHID-XACT-TASK-by2g3dtlfq3l2wc]' => 'PHID-XACT-TASK-by2g3dtlfq3l2wc',
- 'storyAuthorPHID' => 'PHID-USER-fnetlprx7zdotfm2hdrz',
- 'storyText' => 'quux moved T123: Lorem ipsum dolor to Backlog on the Foo workboard.',
- 'epoch' => 1450654419,
- ];
- }
-
- /**
- * Tests a Phabricator gate payload.
- */
- public function testPhabricatorPayload () {
- $data = $this->getDataForPhabricatorPayloadTests();
-
- $this->post('/gate/Phabricator/Acme', $data)->seeJson([
- 'gate' => 'Phabricator',
- 'door' => 'Acme',
- 'action' => 'AMQPAction'
- ]);
- $this->assertResponseOk();
- }
-
- /**
- * Tests a Phabricator gate payload, when the door doesn't exist.
- */
- public function testPhabricatorPayloadOnNotExistingDoor () {
- $data = $this->getDataForPhabricatorPayloadTests();
-
- $this->post('/gate/Phabricator/NotExistingDoor', $data);
- $this->assertResponseStatus(404);
- }
-
- /**
- * Same than testPost, but without actions report.
- */
- public function testPostWithoutActionsReport () {
- Features::disable("ActionsReport");
-
- $this->sendValidTestPayload();
- $this->assertEmpty($this->response->getContent());
- $this->assertResponseOk();
-
- // Let's throw an Exception at broker level.
- // Without ActionsReport, the client must always receive a 200 OK.
-
- $this->app->instance('broker', function ($app) {
- // A non omnipotent instance, so it doesn't mock connect().
- return new BlackholeBroker;
- });
- $this->sendValidTestPayload();
- $this->assertEmpty($this->response->getContent());
- $this->assertResponseOk();
- }
-
- /**
- * Tests a GitHub gate payload.
- */
- public function testInvalidSignature () {
- $this->sendInvalidTestPayload()
- ->assertResponseStatus(403);
- }
-
- public function testBrokerIssue () {
- $this->mockNotOperationalBroker();
-
- $payload = file_get_contents(__DIR__ . '/../data/payloads/GitHubPingPayload.json');
- $this->sendPayload(
- '/gate/GitHub/Acme', // A gate existing in data/credentials.json
- $payload,
- 'POST',
- [
- 'X-Github-Event' => 'ping',
- 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
- 'X-Hub-Signature' => 'sha1=25f6cbd17ea4c6c69958b95fb88c879de4b66dcc',
- ]
- )->seeJson([
- 'gate' => 'GitHub',
- 'door' => 'Acme',
- 'action' => 'AMQPAction',
- 'type' => 'RuntimeException',
- ]);
-
- $this->assertResponseStatus(503);
- }
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->disableBroker();
+ }
+
+ /**
+ * Sends a GitHub ping payload to the application, with a valid signature
+ */
+ protected function sendValidTestPayload() {
+ return $this->sendTestPayload( 'sha1=25f6cbd17ea4c6c69958b95fb88c879de4b66dcc' );
+ }
+
+ /**
+ * Sends a GitHub ping payload to the application, with a valid signature
+ */
+ protected function sendInvalidTestPayload() {
+ return $this->sendTestPayload( 'sha1=somethingwrong' );
+ }
+
+ protected function sendTestPayload( $signature ) {
+ $payload = file_get_contents( __DIR__ . '/../data/payloads/GitHubPingPayload.json' );
+ $this->sendPayload(
+ '/gate/GitHub/Acme', // A gate existing in data/credentials.json
+ $payload,
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
+ 'X-Hub-Signature' => $signature,
+ ]
+ );
+ return $this;
+ }
+
+ /**
+ * Tests a GitHub gate payload.
+ */
+ public function testPost() {
+ $this->sendValidTestPayload()->seeJson( [
+ 'gate' => 'GitHub',
+ 'door' => 'Acme',
+ 'action' => 'AMQPAction'
+ ] );
+
+ $this->assertResponseOk();
+ }
+
+ /**
+ * Tests a DockerHub gate payload.
+ */
+ public function testDockerHubPayload() {
+ $payload = file_get_contents( __DIR__ . '/../data/payloads/DockerHubPushPayload.json' );
+ $this->sendPayload(
+ '/gate/DockerHub/Acme', // A gate existing in data/credentials.json
+ $payload,
+ 'POST',
+ []
+ )->seeJson( [
+ 'gate' => 'DockerHub',
+ 'door' => 'Acme',
+ 'action' => 'AMQPAction'
+ ] );
+ $this->assertResponseOk();
+ }
+
+ /**
+ * Tests a Jenkins gate payload.
+ */
+ public function testJenkinsPayload() {
+ $payload = file_get_contents( __DIR__ . '/../data/payloads/JenkinsPayload.json' );
+
+ $this->sendPayload(
+ '/gate/Jenkins/Acme', // A gate existing in data/credentials.json
+ $payload,
+ 'POST',
+ []
+ )->seeJson( [
+ 'gate' => 'Jenkins',
+ 'door' => 'Acme',
+ 'action' => 'AMQPAction'
+ ] );
+ $this->assertResponseOk();
+ }
+
+ private function getDataForPhabricatorPayloadTests() {
+ return [
+ 'storyID' => 3849,
+ 'storyType' => 'PhabricatorApplicationTransactionFeedStory',
+ 'storyData[objectPHID]' => 'PHID-TASK-l34fw5wievp6n6rnvpuk',
+ 'storyData[transactionPHIDs][PHID-XACT-TASK-by2g3dtlfq3l2wc]' => 'PHID-XACT-TASK-by2g3dtlfq3l2wc',
+ 'storyAuthorPHID' => 'PHID-USER-fnetlprx7zdotfm2hdrz',
+ 'storyText' => 'quux moved T123: Lorem ipsum dolor to Backlog on the Foo workboard.',
+ 'epoch' => 1450654419,
+ ];
+ }
+
+ /**
+ * Tests a Phabricator gate payload.
+ */
+ public function testPhabricatorPayload() {
+ $data = $this->getDataForPhabricatorPayloadTests();
+
+ $this->post( '/gate/Phabricator/Acme', $data )->seeJson( [
+ 'gate' => 'Phabricator',
+ 'door' => 'Acme',
+ 'action' => 'AMQPAction'
+ ] );
+ $this->assertResponseOk();
+ }
+
+ /**
+ * Tests a Phabricator gate payload, when the door doesn't exist.
+ */
+ public function testPhabricatorPayloadOnNotExistingDoor() {
+ $data = $this->getDataForPhabricatorPayloadTests();
+
+ $this->post( '/gate/Phabricator/NotExistingDoor', $data );
+ $this->assertResponseStatus( 404 );
+ }
+
+ /**
+ * Same than testPost, but without actions report.
+ */
+ public function testPostWithoutActionsReport() {
+ Features::disable( "ActionsReport" );
+
+ $this->sendValidTestPayload();
+ $this->assertEmpty( $this->response->getContent() );
+ $this->assertResponseOk();
+
+ // Let's throw an Exception at broker level.
+ // Without ActionsReport, the client must always receive a 200 OK.
+
+ $this->app->instance( 'broker', static function ( $app ) {
+ // A non omnipotent instance, so it doesn't mock connect().
+ return new BlackholeBroker;
+ } );
+ $this->sendValidTestPayload();
+ $this->assertEmpty( $this->response->getContent() );
+ $this->assertResponseOk();
+ }
+
+ /**
+ * Tests a GitHub gate payload.
+ */
+ public function testInvalidSignature() {
+ $this->sendInvalidTestPayload()
+ ->assertResponseStatus( 403 );
+ }
+
+ public function testBrokerIssue() {
+ $this->mockNotOperationalBroker();
+
+ $payload = file_get_contents( __DIR__ . '/../data/payloads/GitHubPingPayload.json' );
+ $this->sendPayload(
+ '/gate/GitHub/Acme', // A gate existing in data/credentials.json
+ $payload,
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
+ 'X-Hub-Signature' => 'sha1=25f6cbd17ea4c6c69958b95fb88c879de4b66dcc',
+ ]
+ )->seeJson( [
+ 'gate' => 'GitHub',
+ 'door' => 'Acme',
+ 'action' => 'AMQPAction',
+ 'type' => 'RuntimeException',
+ ] );
+
+ $this->assertResponseStatus( 503 );
+ }
}
diff --git a/tests/Http/PlaceholderTest.php b/tests/Http/PlaceholderTest.php
--- a/tests/Http/PlaceholderTest.php
+++ b/tests/Http/PlaceholderTest.php
@@ -2,20 +2,15 @@
namespace Nasqueron\Notifications\Tests;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-use Illuminate\Foundation\Testing\DatabaseMigrations;
-use Illuminate\Foundation\Testing\DatabaseTransactions;
-
-class PlaceholderTest extends TestCase
-{
- /**
- * Placeholder homepage works.
- *
- * @return void
- */
- public function testPlaceholder()
- {
- $this->visit('/')
- ->see('Notifications center');
- }
+class PlaceholderTest extends TestCase {
+ /**
+ * Placeholder homepage works.
+ *
+ * @return void
+ * @doesNotPerformAssertions
+ */
+ public function testPlaceholder() {
+ $this->visit( '/' )
+ ->see( 'Notifications center' );
+ }
}
diff --git a/tests/Http/StatusTest.php b/tests/Http/StatusTest.php
--- a/tests/Http/StatusTest.php
+++ b/tests/Http/StatusTest.php
@@ -2,20 +2,15 @@
namespace Nasqueron\Notifications\Tests;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-use Illuminate\Foundation\Testing\DatabaseMigrations;
-use Illuminate\Foundation\Testing\DatabaseTransactions;
-
-class StatusTest extends TestCase
-{
- /**
- * Status works.
- *
- * @return void
- */
- public function testStatus()
- {
- $this->visit('/status')
- ->see('ALIVE');
- }
+class StatusTest extends TestCase {
+ /**
+ * Status works.
+ *
+ * @return void
+ * @doesNotPerformAssertions
+ */
+ public function testStatus() {
+ $this->visit( '/status' )
+ ->see( 'ALIVE' );
+ }
}
diff --git a/tests/Jobs/NotifyNewCommitsToDiffusionTest.php b/tests/Jobs/NotifyNewCommitsToDiffusionTest.php
--- a/tests/Jobs/NotifyNewCommitsToDiffusionTest.php
+++ b/tests/Jobs/NotifyNewCommitsToDiffusionTest.php
@@ -8,63 +8,67 @@
class NotifyNewCommitsToDiffusionTest extends TestCase {
- ///
- /// Tests
- ///
+ ///
+ /// Tests
+ ///
- /**
- * @dataProvider apiRepositoryReplyProvider
- */
- public function testHandle ($apiRepositoryReply, int $apiCallCounts) {
- $this->mockPhabricatorAPI()
- ->shouldReceive('getForProject->call')
- ->andReturn(
- // First API call: repository.query
- $apiRepositoryReply,
+ /**
+ * @dataProvider apiRepositoryReplyProvider
+ */
+ public function testHandle( ?array $apiRepositoryReply, int $apiCallCounts ) {
+ $this->mockPhabricatorAPI()
+ ->shouldReceive( 'getForProject->call' )
+ ->andReturn(
+ // First API call: repository.query
+ $apiRepositoryReply,
- // Second API call: diffusion.looksoon
- null
- )
- ->times($apiCallCounts); // 2 when repository.query is valid
- // 1 otherwise
+ // Second API call: diffusion.looksoon
+ null
+ )
+ ->times( $apiCallCounts ); // 2 when repository.query is valid
+ // 1 otherwise
- $job = $this->mockJob();
- $job->handle();
- }
+ $job = $this->mockJob();
+ $job->handle();
+ }
- public function testJobWhenThereIsNoPhabricatorInstanceForTheProject () {
- $job = $this->mockJob("not-existing-project");
- $job->handle();
- }
+ /**
+ * @doesNotPerformAssertions
+ */
+ public function testJobWhenThereIsNoPhabricatorInstanceForTheProject() {
+ $job = $this->mockJob( "not-existing-project" );
+ $job->handle();
+ }
- ///
- /// Helper methods
- ///
+ ///
+ /// Helper methods
+ ///
- /**
- * Mocks a job
- */
- protected function mockJob(string $project = "acme") : Job {
- return new NotifyNewCommitsToDiffusion(
- $project,
- "ssh://acme/k2.git"
- );
- }
+ /**
+ * Mocks a job
+ */
+ protected function mockJob( string $project = "acme" ): Job {
+ return new NotifyNewCommitsToDiffusion(
+ $project,
+ "ssh://acme/k2.git"
+ );
+ }
- /**
- * Provides API repository reply and associated API calls count
- */
- public function apiRepositoryReplyProvider () : array {
- return [
- // Regular behavior
- [[new class { public $callsign = "K2"; }], 2],
+ /**
+ * Provides API repository reply and associated API calls count
+ */
+ public function apiRepositoryReplyProvider(): array {
+ return [
+ // Regular behavior
+ [ [ new class { public $callsign = "K2";
+ } ], 2 ],
- // Phabricator doesn't know this repo
- [[], 1],
+ // Phabricator doesn't know this repo
+ [ [], 1 ],
- // Some error occurs and the API reply is null
- [null, 1],
- ];
- }
+ // Some error occurs and the API reply is null
+ [ null, 1 ],
+ ];
+ }
}
diff --git a/tests/Notifications/DockerHubNotificationTest.php b/tests/Notifications/DockerHubNotificationTest.php
--- a/tests/Notifications/DockerHubNotificationTest.php
+++ b/tests/Notifications/DockerHubNotificationTest.php
@@ -2,79 +2,77 @@
namespace Nasqueron\Notifications\Tests\Notifications;
-use Nasqueron\Notifications\Notifications\DockerHubNotification;
-use Nasqueron\Notifications\Tests\TestCase;
-
use Keruald\Mailgun\Tests\WithMockHttpClient;
-
use Mockery;
+use Nasqueron\Notifications\Notifications\DockerHubNotification;
+use Nasqueron\Notifications\Tests\TestCase;
class DockerHubNotificationTest extends TestCase {
- use WithMockHttpClient;
-
- /**
- * @return \Nasqueron\Notifications\Notifications\DockerHubNotification
- */
- protected function prepareNotification ($event) {
- $path = __DIR__ . '/../data/payloads/DockerHub' . ucfirst($event)
- . 'Payload.json';
- $payload = json_decode(file_get_contents($path));
-
- return new DockerHubNotification("Acme", $event, $payload);
- }
-
- public function testPropertiesForPush () {
- $notification = $this->prepareNotification("push");
-
- $this->assertSame("DockerHub", $notification->service);
- $this->assertSame("Acme", $notification->project);
- $this->assertSame("docker", $notification->group);
- $this->assertSame("push", $notification->type);
- $this->assertSame(
- "New image pushed to Docker Hub registry for svendowideit/testhook by trustedbuilder",
- $notification->text
- );
- $this->assertSame(
- "https://registry.hub.docker.com/u/svendowideit/testhook/",
- $notification->link
- );
- }
-
- public function testPropertiesForBuildFailure () {
- $this->mockMailgunServiceProvider();
- $notification = $this->prepareNotification("buildFailure");
- $this->assertSame("buildFailure", $notification->type);
-
- $this->assertSame(
- "Image build by Docker Hub registry failure for acme/foo",
- $notification->text
- );
- $this->assertSame(
- "https://hub.docker.com/r/acme/foo/builds/abcdef123456/",
- $notification->link
- );
- }
-
- ///
- /// Helper mock method
- ///
-
- /**
- * Injects into our container a mock of MailgunMessageFactory
- */
- protected function mockMailgunServiceProvider () {
- $mock = Mockery::mock('Keruald\Mailgun\MailgunMessageFactory');
- $payload = $this->mockMailgunResponse();
- $mock->shouldReceive('fetchMessageFromPayload')->once()->andReturn($payload);
- $this->app->instance('mailgun', $mock);
- }
-
- /**
- * @return \stdClass
- */
- protected function mockMailgunResponse () {
- return json_decode($this->mockHttpClientResponseBody());
- }
+ use WithMockHttpClient;
+
+ /**
+ * @return \Nasqueron\Notifications\Notifications\DockerHubNotification
+ */
+ protected function prepareNotification( $event ) {
+ $path = __DIR__ . '/../data/payloads/DockerHub' . ucfirst( $event )
+ . 'Payload.json';
+ $payload = json_decode( file_get_contents( $path ) );
+
+ return new DockerHubNotification( "Acme", $event, $payload );
+ }
+
+ public function testPropertiesForPush() {
+ $notification = $this->prepareNotification( "push" );
+
+ $this->assertSame( "DockerHub", $notification->service );
+ $this->assertSame( "Acme", $notification->project );
+ $this->assertSame( "docker", $notification->group );
+ $this->assertSame( "push", $notification->type );
+ $this->assertSame(
+ "New image pushed to Docker Hub registry for svendowideit/testhook by trustedbuilder",
+ $notification->text
+ );
+ $this->assertSame(
+ "https://registry.hub.docker.com/u/svendowideit/testhook/",
+ $notification->link
+ );
+ }
+
+ public function testPropertiesForBuildFailure() {
+ $this->mockMailgunServiceProvider();
+ $notification = $this->prepareNotification( "buildFailure" );
+ $this->assertSame( "buildFailure", $notification->type );
+
+ $this->assertSame(
+ "Image build by Docker Hub registry failure for acme/foo",
+ $notification->text
+ );
+ $this->assertSame(
+ "https://hub.docker.com/r/acme/foo/builds/abcdef123456/",
+ $notification->link
+ );
+ }
+
+ ///
+ /// Helper mock method
+ ///
+
+ /**
+ * Injects into our container a mock of MailgunMessageFactory
+ */
+ protected function mockMailgunServiceProvider() {
+ $mock = Mockery::mock( 'Keruald\Mailgun\MailgunMessageFactory' );
+ $payload = $this->mockMailgunResponse();
+ $mock->shouldReceive( 'fetchMessageFromPayload' )->once()->andReturn( $payload );
+ $this->app->instance( 'mailgun', $mock );
+ }
+
+ /**
+ * @return \stdClass
+ */
+ protected function mockMailgunResponse() {
+ return json_decode( $this->mockHttpClientResponseBody() );
+ }
}
diff --git a/tests/Notifications/JenkinsNotificationTest.php b/tests/Notifications/JenkinsNotificationTest.php
--- a/tests/Notifications/JenkinsNotificationTest.php
+++ b/tests/Notifications/JenkinsNotificationTest.php
@@ -6,61 +6,61 @@
use Nasqueron\Notifications\Tests\TestCase;
class JenkinsNotificationTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Notifications\JenkinsNotification
- */
- private $notification;
+ /**
+ * @var \Nasqueron\Notifications\Notifications\JenkinsNotification
+ */
+ private $notification;
- /**
- * @var \stdClass
- */
- private $payload;
+ /**
+ * @var \stdClass
+ */
+ private $payload;
- public function prepareNotification ($payloadFile, $project = "Acme") {
- $path = __DIR__ . '/../data/payloads/' . $payloadFile;
- $this->payload = json_decode(file_get_contents($path));
+ public function prepareNotification( $payloadFile, $project = "Acme" ) {
+ $path = __DIR__ . '/../data/payloads/' . $payloadFile;
+ $this->payload = json_decode( file_get_contents( $path ) );
- $this->notification = new JenkinsNotification(
- $project,
- $this->payload
- );
- }
+ $this->notification = new JenkinsNotification(
+ $project,
+ $this->payload
+ );
+ }
- public function testProperties () {
- $this->prepareNotification('JenkinsPayload.json');
+ public function testProperties() {
+ $this->prepareNotification( 'JenkinsPayload.json' );
- $this->assertSame("Jenkins", $this->notification->service);
- $this->assertSame("Acme", $this->notification->project);
- $this->assertSame("ci", $this->notification->group);
- $this->assertSame($this->payload, $this->notification->rawContent);
- $this->assertSame("completed.success", $this->notification->type);
- $this->assertSame(
- "Jenkins job asgard has been completed: success",
- $this->notification->text
- );
- $this->assertSame(
- "http://localhost:8080/job/asgard/18/",
- $this->notification->link
- );
- }
+ $this->assertSame( "Jenkins", $this->notification->service );
+ $this->assertSame( "Acme", $this->notification->project );
+ $this->assertSame( "ci", $this->notification->group );
+ $this->assertSame( $this->payload, $this->notification->rawContent );
+ $this->assertSame( "completed.success", $this->notification->type );
+ $this->assertSame(
+ "Jenkins job asgard has been completed: success",
+ $this->notification->text
+ );
+ $this->assertSame(
+ "http://localhost:8080/job/asgard/18/",
+ $this->notification->link
+ );
+ }
- public function testPropertiesForIncompletePayload () {
- $this->prepareNotification('JenkinsStartedPayload.json');
+ public function testPropertiesForIncompletePayload() {
+ $this->prepareNotification( 'JenkinsStartedPayload.json' );
- $this->assertSame("started", $this->notification->type);
- $this->assertSame(
- "Jenkins job asgard has been started",
- $this->notification->text
- );
- }
+ $this->assertSame( "started", $this->notification->type );
+ $this->assertSame(
+ "Jenkins job asgard has been started",
+ $this->notification->text
+ );
+ }
- public function testShouldNotifyOnDefaultConfiguration () {
- $this->prepareNotification('JenkinsPayload.json');
- $this->assertTrue($this->notification->shouldNotify());
- }
+ public function testShouldNotifyOnDefaultConfiguration() {
+ $this->prepareNotification( 'JenkinsPayload.json' );
+ $this->assertTrue( $this->notification->shouldNotify() );
+ }
- public function testShouldNotifyWhenConfiguredNotTo () {
- $this->prepareNotification('JenkinsToIgnorePayload.json', 'Nasqueron');
- $this->assertFalse($this->notification->shouldNotify());
- }
+ public function testShouldNotifyWhenConfiguredNotTo() {
+ $this->prepareNotification( 'JenkinsToIgnorePayload.json', 'Nasqueron' );
+ $this->assertFalse( $this->notification->shouldNotify() );
+ }
}
diff --git a/tests/Phabricator/PhabricatorAPIExceptionTest.php b/tests/Phabricator/PhabricatorAPIExceptionTest.php
--- a/tests/Phabricator/PhabricatorAPIExceptionTest.php
+++ b/tests/Phabricator/PhabricatorAPIExceptionTest.php
@@ -7,23 +7,23 @@
class PhabricatorAPIExceptionTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Phabricator\PhabricatorAPIException
- */
- private $exception;
+ /**
+ * @var \Nasqueron\Notifications\Phabricator\PhabricatorAPIException
+ */
+ private $exception;
- public function setUp () {
- $this->exception = new PhabricatorAPIException(
- 100,
- "Lorem ipsum dolor"
- );
- }
+ public function setUp(): void {
+ $this->exception = new PhabricatorAPIException(
+ 100,
+ "Lorem ipsum dolor"
+ );
+ }
- public function testGetCode () {
- $this->assertSame(100, $this->exception->getCode());
- }
+ public function testGetCode() {
+ $this->assertSame( 100, $this->exception->getCode() );
+ }
- public function testGetMessage () {
- $this->assertSame("Lorem ipsum dolor", $this->exception->getMessage());
- }
+ public function testGetMessage() {
+ $this->assertSame( "Lorem ipsum dolor", $this->exception->getMessage() );
+ }
}
diff --git a/tests/Phabricator/PhabricatorAPIFactoryTest.php b/tests/Phabricator/PhabricatorAPIFactoryTest.php
--- a/tests/Phabricator/PhabricatorAPIFactoryTest.php
+++ b/tests/Phabricator/PhabricatorAPIFactoryTest.php
@@ -6,27 +6,27 @@
class PhabricatorAPIFactoryTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Phabricator\ProjectsMapFactory
- */
- private $factory;
+ /**
+ * @var \Nasqueron\Notifications\Phabricator\ProjectsMapFactory
+ */
+ private $factory;
- public function setUp () {
- parent::setUp();
- $this->factory = $this->app->make('phabricator-api');
- }
+ public function setUp(): void {
+ parent::setUp();
+ $this->factory = $this->app->make( 'phabricator-api' );
+ }
- public function testGetAPI () {
- $this->assertInstanceOf(
- '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
- $this->factory->get("https://phabricator.acme.tld")
- );
- }
+ public function testGetAPI() {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
+ $this->factory->get( "https://phabricator.acme.tld" )
+ );
+ }
- public function testGetAPIForProject () {
- $this->assertInstanceOf(
- '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
- $this->factory->getForProject("Acme")
- );
- }
+ public function testGetAPIForProject() {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
+ $this->factory->getForProject( "Acme" )
+ );
+ }
}
diff --git a/tests/Phabricator/PhabricatorAPITest.php b/tests/Phabricator/PhabricatorAPITest.php
--- a/tests/Phabricator/PhabricatorAPITest.php
+++ b/tests/Phabricator/PhabricatorAPITest.php
@@ -6,31 +6,27 @@
use Nasqueron\Notifications\Tests\TestCase;
class PhabricatorAPITest extends TestCase {
- public function testForInstance () {
- $this->assertInstanceOf(
- '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
- PhabricatorAPI::forInstance("https://phabricator.acme.tld")
- );
- }
+ public function testForInstance() {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
+ PhabricatorAPI::forInstance( "https://phabricator.acme.tld" )
+ );
+ }
- public function testForProject () {
- $this->assertInstanceOf(
- '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
- PhabricatorAPI::forInstance("https://phabricator.acme.tld")
- );
- }
+ public function testForProject() {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\PhabricatorAPI',
+ PhabricatorAPI::forInstance( "https://phabricator.acme.tld" )
+ );
+ }
- /**
- * @expectedException \RuntimeException
- */
- public function testForInstanceWhere () {
- PhabricatorAPI::forInstance("https://notfound.acme.tld");
- }
+ public function testForInstanceWhere() {
+ $this->expectException( \RuntimeException::class );
+ PhabricatorAPI::forInstance( "https://notfound.acme.tld" );
+ }
- /**
- * @expectedException \RuntimeException
- */
- public function testForProjectWhenProjectDoesNotExist () {
- PhabricatorAPI::forProject("NotFound");
- }
+ public function testForProjectWhenProjectDoesNotExist() {
+ $this->expectException( \RuntimeException::class );
+ PhabricatorAPI::forProject( "NotFound" );
+ }
}
diff --git a/tests/Phabricator/PhabricatorStoryTest.php b/tests/Phabricator/PhabricatorStoryTest.php
--- a/tests/Phabricator/PhabricatorStoryTest.php
+++ b/tests/Phabricator/PhabricatorStoryTest.php
@@ -6,38 +6,38 @@
use Nasqueron\Notifications\Tests\TestCase;
class PhabricatorStoryTest extends TestCase {
- /**
- * @dataProvider provideStories
- */
- public function testGetObjectType ($expected, $data) {
- $story = new PhabricatorStory('acme');
- $story->data = $data;
+ /**
+ * @dataProvider provideStories
+ */
+ public function testGetObjectType( string $expected, ?array $data ) {
+ $story = new PhabricatorStory( 'acme' );
+ $story->data = $data;
- $this->assertEquals($expected, $story->getObjectType());
- }
+ $this->assertEquals( $expected, $story->getObjectType() );
+ }
- public function provideStories () : iterable {
- yield ["VOID", null];
- yield ["VOID", []];
- yield ["VOID", ['foo' => 'bar']];
- yield ["TASK", ['objectPHID' => 'PHID-TASK-l34fw5wievp6n6rnvpuk']];
- }
+ public function provideStories(): iterable {
+ yield [ "VOID", null ];
+ yield [ "VOID", [] ];
+ yield [ "VOID", [ 'foo' => 'bar' ] ];
+ yield [ "TASK", [ 'objectPHID' => 'PHID-TASK-l34fw5wievp6n6rnvpuk' ] ];
+ }
- /**
- * @dataProvider provideKeys
- */
- public function testMapPhabricatorFeedKey ($expected, $key) {
- $this->assertEquals(
- $expected,
- PhabricatorStory::mapPhabricatorFeedKey($key)
- );
- }
+ /**
+ * @dataProvider provideKeys
+ */
+ public function testMapPhabricatorFeedKey( string $expected, string $key ) {
+ $this->assertEquals(
+ $expected,
+ PhabricatorStory::mapPhabricatorFeedKey( $key )
+ );
+ }
- public function provideKeys () : iterable {
- yield ['id', 'storyID'];
- yield ['id', 'storyId'];
- yield ['task', 'storyTask'];
- yield ['story', 'story'];
- yield ['', ''];
- }
+ public function provideKeys(): iterable {
+ yield [ 'id', 'storyID' ];
+ yield [ 'id', 'storyId' ];
+ yield [ 'task', 'storyTask' ];
+ yield [ 'story', 'story' ];
+ yield [ '', '' ];
+ }
}
diff --git a/tests/Phabricator/ProjectsMapFactoryTest.php b/tests/Phabricator/ProjectsMapFactoryTest.php
--- a/tests/Phabricator/ProjectsMapFactoryTest.php
+++ b/tests/Phabricator/ProjectsMapFactoryTest.php
@@ -6,30 +6,30 @@
class ProjectsMapFactoryTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Phabricator\ProjectsMapFactory
- */
- private $factory;
-
- public function setUp () {
- parent::setUp();
- $this->factory = $this->app->make('phabricator-projectsmap');
-
- $this->mockPhabricatorAPIForProjectsMap();
- }
-
- public function testLoadProjectsMap () {
- $this->assertInstanceOf(
- '\Nasqueron\Notifications\Phabricator\ProjectsMap',
- $this->factory->load("Acme")
- );
- }
-
- public function testFetchProjectsMap () {
- $this->assertInstanceOf(
- '\Nasqueron\Notifications\Phabricator\ProjectsMap',
- $this->factory->fetch("Acme")
- );
- }
+ /**
+ * @var \Nasqueron\Notifications\Phabricator\ProjectsMapFactory
+ */
+ private $factory;
+
+ public function setUp(): void {
+ parent::setUp();
+ $this->factory = $this->app->make( 'phabricator-projectsmap' );
+
+ $this->mockPhabricatorAPIForProjectsMap();
+ }
+
+ public function testLoadProjectsMap() {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\ProjectsMap',
+ $this->factory->load( "Acme" )
+ );
+ }
+
+ public function testFetchProjectsMap() {
+ $this->assertInstanceOf(
+ '\Nasqueron\Notifications\Phabricator\ProjectsMap',
+ $this->factory->fetch( "Acme" )
+ );
+ }
}
diff --git a/tests/Phabricator/ProjectsMapTest.php b/tests/Phabricator/ProjectsMapTest.php
--- a/tests/Phabricator/ProjectsMapTest.php
+++ b/tests/Phabricator/ProjectsMapTest.php
@@ -6,198 +6,191 @@
use Nasqueron\Notifications\Phabricator\ProjectsMap;
use Nasqueron\Notifications\Tests\TestCase;
-use Mockery;
-
class ProjectsMapTest extends TestCase {
- /**
- * @var \Nasqueron\Notifications\Phabricator\ProjectsMap
- */
- private $map;
-
- public function setUp () {
- parent::setUp();
-
- //
- // We mock the API, so an imaginary instance of Phabricator
- // will return 3 results: Accounts, Agora & architecture.
- //
- // Agora has the key "PHID-PROJ-cztcgpvqr6smnnekotq7".
- //
-
- $this->mockPhabricatorAPIForProjectsMap();
- $this->map = ProjectsMap::fetch("http://phabricator.acme.tld");
- }
-
- public function testIteratorIsTraversable () {
- $this->assertInstanceOf(
- "Traversable",
- $this->map->getIterator()
- );
- }
-
- ///
- /// Tests for ArrayAccess
- ///
-
- public function testOffsetExistsWhenItDoes () {
- $this->assertTrue(
- $this->map->offsetExists("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- public function testOffsetExistsWhenItDoesNot () {
- $this->assertFalse(
- $this->map->offsetExists("non-existing-key")
- );
- }
-
- public function testOffsetGetWhenItDoesExist () {
- $this->assertSame(
- "Agora",
- $this->map->offsetGet("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- /**
- * @expectedException ErrorException
- */
- public function testOffsetGetWhenItDoesNotExist () {
- $this->map->offsetGet("non-existing-key");
- }
-
- /**
- * @covers Nasqueron\Notifications\Phabricator\ProjectsMap::offsetSet
- */
- public function testOffsetSet () {
- $this->map->offsetSet("newkey", "quux");
- $this->assertSame("quux", $this->map->offsetGet("newkey"));
- }
-
- /**
- * @covers Nasqueron\Notifications\Phabricator\ProjectsMap::offsetUnset
- */
- public function testOffsetUnset () {
- unset($this->map["PHID-PROJ-cztcgpvqr6smnnekotq7"]);
- $this->assertFalse(
- $this->map->offsetExists("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- ///
- /// Tests for cache
- ///
-
- public function testCache () {
- $this->assertFalse($this->map->isCached());
- $this->map->saveToCache();
- $this->assertTrue($this->map->isCached());
- }
-
- public function testLoadFromCache () {
- $this->map->saveToCache();
-
- $map = new ProjectsMap("http://phabricator.acme.tld");
- $map->loadFromCache();
-
- $this->assertTrue(
- $map->offsetExists("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- public function testLoadWhenInCache () {
- $this->map->saveToCache();
-
- $map = ProjectsMap::load("http://phabricator.acme.tld");
- $this->assertTrue(
- $map->offsetExists("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- ///
- /// Tests for helper methods
- ///
-
- public function testGetProjectName () {
- $this->assertSame(
- "Agora",
- $this->map->getProjectName("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- public function testGetProjectNameForNewInstance () {
- $map = new ProjectsMap("http://phabricator.acme.tld");
- $this->assertSame(
- "Agora",
- $map->getProjectName("PHID-PROJ-cztcgpvqr6smnnekotq7")
- );
- }
-
- public function testGetProjectNameWhenItDoesNotExist () {
- $this->assertSame(
- "",
- $this->map->getProjectName("non-existing-key")
- );
- }
-
- public function testToArrayProducesArray () {
- $array = $this->map->toArray();
- $this->assertTrue(
- is_array($array),
- "Test if toArray return an array"
- );
- }
-
- public function testThatArrayCount () {
- $array = $this->map->toArray();
- $this->assertSame(3, count($array));
- }
-
- public function testThatArrayContainsExpectedData () {
- $this->assertSame(
- [
- ["PHID-PROJ-6dg6ogx5pjmk24ur4tp4", "Accounts"],
- ["PHID-PROJ-cztcgpvqr6smnnekotq7", "Agora"],
- ["PHID-PROJ-3iew3cqf3htpazfyzb5a", "architecture"]
- ],
- $this->map->toArray()
- );
- }
-
- ///
- /// Tests API
- ///
-
- private function mockPhabricatorAPIWithReply ($reply) : APIClient {
- return (new class($reply) implements APIClient {
- private $reply;
-
- public function __construct ($reply) {
- $this->reply = $reply;
- }
-
- public function setEndPoint ($url) : void { }
-
- public function call ($method, $arguments = []) {
- return $this->reply;
- }
- });
- }
-
- /**
- * @expectedException Exception
- */
- public function testFetchFromAPIWithoutReply () {
- $mock = $this->mockPhabricatorAPIWithReply(false);
- ProjectsMap::fetch("http://phabricator.acme.tld", $mock);
- }
-
- /**
- * @expectedException Exception
- */
- public function testFetchFromAPIInvalidReply () {
- $mock = $this->mockPhabricatorAPIWithReply(new \stdClass);
- ProjectsMap::fetch("http://phabricator.acme.tld", $mock);
- }
+ /**
+ * @var \Nasqueron\Notifications\Phabricator\ProjectsMap
+ */
+ private $map;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ //
+ // We mock the API, so an imaginary instance of Phabricator
+ // will return 3 results: Accounts, Agora & architecture.
+ //
+ // Agora has the key "PHID-PROJ-cztcgpvqr6smnnekotq7".
+ //
+
+ $this->mockPhabricatorAPIForProjectsMap();
+ $this->map = ProjectsMap::fetch( "http://phabricator.acme.tld" );
+ }
+
+ public function testIteratorIsTraversable() {
+ $this->assertInstanceOf(
+ "Traversable",
+ $this->map->getIterator()
+ );
+ }
+
+ ///
+ /// Tests for ArrayAccess
+ ///
+
+ public function testOffsetExistsWhenItDoes() {
+ $this->assertTrue(
+ $this->map->offsetExists( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ public function testOffsetExistsWhenItDoesNot() {
+ $this->assertFalse(
+ $this->map->offsetExists( "non-existing-key" )
+ );
+ }
+
+ public function testOffsetGetWhenItDoesExist() {
+ $this->assertSame(
+ "Agora",
+ $this->map->offsetGet( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ public function testOffsetGetWhenItDoesNotExist() {
+ $this->expectException( \ErrorException::class );
+ $this->map->offsetGet( "non-existing-key" );
+ }
+
+ /**
+ * @covers Nasqueron\Notifications\Phabricator\ProjectsMap::offsetSet
+ */
+ public function testOffsetSet() {
+ $this->map->offsetSet( "newkey", "quux" );
+ $this->assertSame( "quux", $this->map->offsetGet( "newkey" ) );
+ }
+
+ /**
+ * @covers Nasqueron\Notifications\Phabricator\ProjectsMap::offsetUnset
+ */
+ public function testOffsetUnset() {
+ unset( $this->map["PHID-PROJ-cztcgpvqr6smnnekotq7"] );
+ $this->assertFalse(
+ $this->map->offsetExists( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ ///
+ /// Tests for cache
+ ///
+
+ public function testCache() {
+ $this->assertFalse( $this->map->isCached() );
+ $this->map->saveToCache();
+ $this->assertTrue( $this->map->isCached() );
+ }
+
+ public function testLoadFromCache() {
+ $this->map->saveToCache();
+
+ $map = new ProjectsMap( "http://phabricator.acme.tld" );
+ $map->loadFromCache();
+
+ $this->assertTrue(
+ $map->offsetExists( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ public function testLoadWhenInCache() {
+ $this->map->saveToCache();
+
+ $map = ProjectsMap::load( "http://phabricator.acme.tld" );
+ $this->assertTrue(
+ $map->offsetExists( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ ///
+ /// Tests for helper methods
+ ///
+
+ public function testGetProjectName() {
+ $this->assertSame(
+ "Agora",
+ $this->map->getProjectName( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ public function testGetProjectNameForNewInstance() {
+ $map = new ProjectsMap( "http://phabricator.acme.tld" );
+ $this->assertSame(
+ "Agora",
+ $map->getProjectName( "PHID-PROJ-cztcgpvqr6smnnekotq7" )
+ );
+ }
+
+ public function testGetProjectNameWhenItDoesNotExist() {
+ $this->assertSame(
+ "",
+ $this->map->getProjectName( "non-existing-key" )
+ );
+ }
+
+ public function testToArrayProducesArray() {
+ $array = $this->map->toArray();
+ $this->assertTrue(
+ is_array( $array ),
+ "Test if toArray return an array"
+ );
+ }
+
+ public function testThatArrayCount() {
+ $array = $this->map->toArray();
+ $this->assertCount( 3, $array );
+ }
+
+ public function testThatArrayContainsExpectedData() {
+ $this->assertSame(
+ [
+ [ "PHID-PROJ-6dg6ogx5pjmk24ur4tp4", "Accounts" ],
+ [ "PHID-PROJ-cztcgpvqr6smnnekotq7", "Agora" ],
+ [ "PHID-PROJ-3iew3cqf3htpazfyzb5a", "architecture" ]
+ ],
+ $this->map->toArray()
+ );
+ }
+
+ ///
+ /// Tests API
+ ///
+
+ private function mockPhabricatorAPIWithReply( $reply ): APIClient {
+ return ( new class( $reply ) implements APIClient {
+ private $reply;
+
+ public function __construct( $reply ) {
+ $this->reply = $reply;
+ }
+
+ public function setEndPoint( $url ): void {
+ }
+
+ public function call( $method, $arguments = [] ) {
+ return $this->reply;
+ }
+ } );
+ }
+
+ public function testFetchFromAPIWithoutReply() {
+ $this->expectException( \Exception::class );
+ $mock = $this->mockPhabricatorAPIWithReply( false );
+ ProjectsMap::fetch( "http://phabricator.acme.tld", $mock );
+ }
+
+ public function testFetchFromAPIInvalidReply() {
+ $this->expectException( \Exception::class );
+ $mock = $this->mockPhabricatorAPIWithReply( new \stdClass );
+ ProjectsMap::fetch( "http://phabricator.acme.tld", $mock );
+ }
}
diff --git a/tests/Providers/AppServiceProviderTest.php b/tests/Providers/AppServiceProviderTest.php
--- a/tests/Providers/AppServiceProviderTest.php
+++ b/tests/Providers/AppServiceProviderTest.php
@@ -4,11 +4,11 @@
class AppServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Illuminate\Contracts\Foundation\Application',
- 'app'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Illuminate\Contracts\Foundation\Application',
+ 'app'
+ );
+ }
}
diff --git a/tests/Providers/BrokerServiceProviderTest.php b/tests/Providers/BrokerServiceProviderTest.php
--- a/tests/Providers/BrokerServiceProviderTest.php
+++ b/tests/Providers/BrokerServiceProviderTest.php
@@ -4,11 +4,11 @@
class BrokerServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Keruald\Broker\Broker',
- 'broker'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Keruald\Broker\Broker',
+ 'broker'
+ );
+ }
}
diff --git a/tests/Providers/ConfigTest.php b/tests/Providers/ConfigTest.php
--- a/tests/Providers/ConfigTest.php
+++ b/tests/Providers/ConfigTest.php
@@ -6,38 +6,38 @@
use File;
class ConfigTest extends TestCase {
- /**
- * The actual list of services providers
- *
- * @var string[]
- */
- private $providers;
-
- /**
- * The service providers' namespace
- *
- * @var string
- */
- private $namespace;
-
- public function setUp () {
- parent::setUp();
-
- $this->providers = Config::get('app.providers');
- $this->namespace = $this->app->getInstance()->getNamespace()
- . 'Providers\\';
- }
-
- public function testOmittedFiles () {
- $files = File::allFiles(app_path('Providers'));
-
- foreach ($files as $file) {
- $class = $this->namespace . $file->getBasename('.php');
- $this->assertContains(
- $class, $this->providers,
- "The class $class should be added to config/app.php in the " .
- "providers array."
- );
- }
- }
+ /**
+ * The actual list of services providers
+ *
+ * @var string[]
+ */
+ private $providers;
+
+ /**
+ * The service providers' namespace
+ *
+ * @var string
+ */
+ private $namespace;
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->providers = Config::get( 'app.providers' );
+ $this->namespace = $this->app->getInstance()->getNamespace()
+ . 'Providers\\';
+ }
+
+ public function testOmittedFiles() {
+ $files = File::allFiles( app_path( 'Providers' ) );
+
+ foreach ( $files as $file ) {
+ $class = $this->namespace . $file->getBasename( '.php' );
+ $this->assertContains(
+ $class, $this->providers,
+ "The class $class should be added to config/app.php in the " .
+ "providers array."
+ );
+ }
+ }
}
diff --git a/tests/Providers/DockerHubServiceProviderTest.php b/tests/Providers/DockerHubServiceProviderTest.php
--- a/tests/Providers/DockerHubServiceProviderTest.php
+++ b/tests/Providers/DockerHubServiceProviderTest.php
@@ -2,35 +2,34 @@
namespace Nasqueron\Notifications\Tests\Providers;
-use Nasqueron\Notifications\Providers\DockerHubServiceProvider;
-
use Config;
+use Nasqueron\Notifications\Providers\DockerHubServiceProvider;
class DockerHubServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Keruald\DockerHub\Build\TriggerBuildFactory',
- 'dockerhub'
- );
- }
-
- public function testGetTokens () {
- $this->assertSame(
- ['acme/foo' => '0000'],
- DockerHubServiceProvider::getTokens($this->app),
- "The service provider should deserialize DockerHubTokens.json."
- );
- }
-
- public function testGetTokensWhenFileDoesNotExist () {
- Config::set('services.dockerhub.tokens', 'notexisting.json');
-
- $this->assertSame(
- [],
- DockerHubServiceProvider::getTokens($this->app),
- "When no tokens file exists, an empty array is used instead."
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Keruald\DockerHub\Build\TriggerBuildFactory',
+ 'dockerhub'
+ );
+ }
+
+ public function testGetTokens() {
+ $this->assertSame(
+ [ 'acme/foo' => '0000' ],
+ DockerHubServiceProvider::getTokens( $this->app ),
+ "The service provider should deserialize DockerHubTokens.json."
+ );
+ }
+
+ public function testGetTokensWhenFileDoesNotExist() {
+ Config::set( 'services.dockerhub.tokens', 'notexisting.json' );
+
+ $this->assertSame(
+ [],
+ DockerHubServiceProvider::getTokens( $this->app ),
+ "When no tokens file exists, an empty array is used instead."
+ );
+ }
}
diff --git a/tests/Providers/EventServiceProviderTest.php b/tests/Providers/EventServiceProviderTest.php
--- a/tests/Providers/EventServiceProviderTest.php
+++ b/tests/Providers/EventServiceProviderTest.php
@@ -7,33 +7,34 @@
class EventServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Illuminate\Contracts\Events\Dispatcher',
- 'events'
- );
- }
-
- ///
- /// Tests specific to this service provider
- ///
-
- public function testOmittedFiles () {
- $subscribe = [];
-
- $namespace = $this->app->getInstance()->getNamespace() . 'Listeners\\';
- $files = File::allFiles(app_path('Listeners'));
- foreach ($files as $file) {
- $class = $namespace . $file->getBasename('.php');
- $subscribe[] = $class;
- }
-
- $this->assertEquals(
- $subscribe, Config::get('app.listeners'),
- 'The files in the app/Listeners folder and the array of classes ' .
- 'defined in config/app.php at listeners key diverge.',
- 0.0, 10, true // delta, maxDepth, canonicalize
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Illuminate\Contracts\Events\Dispatcher',
+ 'events'
+ );
+ }
+
+ ///
+ /// Tests specific to this service provider
+ ///
+
+ public function testOmittedFiles() {
+ $subscribe = [];
+
+ $namespace = $this->app->getInstance()->getNamespace() . 'Listeners\\';
+ $files = File::allFiles( app_path( 'Listeners' ) );
+ foreach ( $files as $file ) {
+ $class = $namespace . $file->getBasename( '.php' );
+ $subscribe[] = $class;
+ }
+
+ $this->assertEquals(
+ $subscribe, Config::get( 'app.listeners' ),
+ 'The files in the app/Listeners folder and the array of classes ' .
+ 'defined in config/app.php at listeners key diverge.' // delta, maxDepth, canonicalize
+ );
+ $this->assertEqualsCanonicalizing( $subscribe, Config::get( 'app.listeners' ), 'The files in the app/Listeners folder and the array of classes ' .
+ 'defined in config/app.php at listeners key diverge.' );
+ }
}
diff --git a/tests/Providers/MailgunServiceProviderTest.php b/tests/Providers/MailgunServiceProviderTest.php
--- a/tests/Providers/MailgunServiceProviderTest.php
+++ b/tests/Providers/MailgunServiceProviderTest.php
@@ -4,11 +4,11 @@
class MailgunServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Keruald\Mailgun\MailgunMessageFactory',
- 'mailgun'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Keruald\Mailgun\MailgunMessageFactory',
+ 'mailgun'
+ );
+ }
}
diff --git a/tests/Providers/PhabricatorAPIServiceProviderTest.php b/tests/Providers/PhabricatorAPIServiceProviderTest.php
--- a/tests/Providers/PhabricatorAPIServiceProviderTest.php
+++ b/tests/Providers/PhabricatorAPIServiceProviderTest.php
@@ -4,11 +4,11 @@
class PhabricatorAPIServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory',
- 'phabricator-api'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory',
+ 'phabricator-api'
+ );
+ }
}
diff --git a/tests/Providers/PhabricatorProjectsMapServiceProviderTest.php b/tests/Providers/PhabricatorProjectsMapServiceProviderTest.php
--- a/tests/Providers/PhabricatorProjectsMapServiceProviderTest.php
+++ b/tests/Providers/PhabricatorProjectsMapServiceProviderTest.php
@@ -4,11 +4,11 @@
class PhabricatorProjectsMapServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Nasqueron\Notifications\Phabricator\ProjectsMapFactory',
- 'phabricator-projectsmap'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Nasqueron\Notifications\Phabricator\ProjectsMapFactory',
+ 'phabricator-projectsmap'
+ );
+ }
}
diff --git a/tests/Providers/ReportServiceProviderTest.php b/tests/Providers/ReportServiceProviderTest.php
--- a/tests/Providers/ReportServiceProviderTest.php
+++ b/tests/Providers/ReportServiceProviderTest.php
@@ -4,27 +4,27 @@
class ReportServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Nasqueron\Notifications\Actions\ActionsReport',
- 'report'
- );
- }
-
- ///
- /// Tests specific to this service provider
- ///
-
- public function testEvents () {
- $dispatcher = $this->app->make('events');
- $type = 'Nasqueron\Notifications\Events\ReportEvent';
-
- // Currently, we don't have listener for ReportEvent.
- $this->assertFalse($dispatcher->hasListeners($type));
-
- // When we resolve an instance of our object in the container, we have.
- $this->app->make('report');
- $this->assertTrue($dispatcher->hasListeners($type));
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Nasqueron\Notifications\Actions\ActionsReport',
+ 'report'
+ );
+ }
+
+ ///
+ /// Tests specific to this service provider
+ ///
+
+ public function testEvents() {
+ $dispatcher = $this->app->make( 'events' );
+ $type = 'Nasqueron\Notifications\Events\ReportEvent';
+
+ // Currently, we don't have listener for ReportEvent.
+ $this->assertFalse( $dispatcher->hasListeners( $type ) );
+
+ // When we resolve an instance of our object in the container, we have.
+ $this->app->make( 'report' );
+ $this->assertTrue( $dispatcher->hasListeners( $type ) );
+ }
}
diff --git a/tests/Providers/RouteServiceProviderTest..php b/tests/Providers/RouteServiceProviderTest..php
--- a/tests/Providers/RouteServiceProviderTest..php
+++ b/tests/Providers/RouteServiceProviderTest..php
@@ -4,11 +4,11 @@
class BrokerServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Illuminate\Routing\Router',
- 'router'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Illuminate\Routing\Router',
+ 'router'
+ );
+ }
}
diff --git a/tests/Providers/SentryServiceProviderTest.php b/tests/Providers/SentryServiceProviderTest.php
--- a/tests/Providers/SentryServiceProviderTest.php
+++ b/tests/Providers/SentryServiceProviderTest.php
@@ -4,11 +4,11 @@
class SentryServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- 'Raven_Client',
- 'raven'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ 'Raven_Client',
+ 'raven'
+ );
+ }
}
diff --git a/tests/Providers/ServicesServiceProviderTest.php b/tests/Providers/ServicesServiceProviderTest.php
--- a/tests/Providers/ServicesServiceProviderTest.php
+++ b/tests/Providers/ServicesServiceProviderTest.php
@@ -2,40 +2,38 @@
namespace Nasqueron\Notifications\Tests\Providers;
-use Nasqueron\Notifications\Providers\ServicesServiceProvider;
-
use Config;
class ServicesServiceProviderTest extends TestCase {
- public function testType () {
- $this->assertServiceInstanceOf(
- "Nasqueron\Notifications\Config\Services\Services",
- 'services'
- );
- }
+ public function testType() {
+ $this->assertServiceInstanceOf(
+ "Nasqueron\Notifications\Config\Services\Services",
+ 'services'
+ );
+ }
- ///
- /// Tests specific to this service provider
- ///
+ ///
+ /// Tests specific to this service provider
+ ///
- public function testWithCredentialsFile () {
- $services = $this->app->make('services');
+ public function testWithCredentialsFile() {
+ $services = $this->app->make( 'services' );
- $this->assertGreaterThan(0, count($services->services));
- }
+ $this->assertGreaterThan( 0, count( $services->services ) );
+ }
- public function testWithoutCredentialsFile () {
- Config::set('services.gate.credentials', null);
- $services = $this->app->make('services');
+ public function testWithoutCredentialsFile() {
+ Config::set( 'services.gate.credentials', null );
+ $services = $this->app->make( 'services' );
- $this->assertSame(0, count($services->services));
- }
+ $this->assertCount( 0, $services->services );
+ }
- public function testWithNontFoundCredentialsFile () {
- Config::set('services.gate.credentials', 'notfound.json');
- $services = $this->app->make('services');
+ public function testWithNontFoundCredentialsFile() {
+ Config::set( 'services.gate.credentials', 'notfound.json' );
+ $services = $this->app->make( 'services' );
- $this->assertSame(0, count($services->services));
- }
+ $this->assertCount( 0, $services->services );
+ }
}
diff --git a/tests/Providers/TestCase.php b/tests/Providers/TestCase.php
--- a/tests/Providers/TestCase.php
+++ b/tests/Providers/TestCase.php
@@ -6,15 +6,15 @@
class TestCase extends BaseTestCase {
- /**
- * Asserts a service in the application container is from the expected type.
- *
- * @param $expectedType The type to check
- * @param $serviceName The service name to use as application container key
- */
- public function assertServiceInstanceOf ($expectedType, $serviceName) {
- $service = $this->app->make($serviceName);
- $this->assertInstanceOf($expectedType, $service);
- }
+ /**
+ * Asserts a service in the application container is from the expected type.
+ *
+ * @param $expectedType The type to check
+ * @param $serviceName The service name to use as application container key
+ */
+ public function assertServiceInstanceOf( $expectedType, $serviceName ) {
+ $service = $this->app->make( $serviceName );
+ $this->assertInstanceOf( $expectedType, $service );
+ }
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,165 +2,153 @@
namespace Nasqueron\Notifications\Tests;
-use Nasqueron\Notifications\Config\Services\Service;
-
use Illuminate\Contracts\Console\Kernel;
use Keruald\Broker\BlackholeBroker;
-use Keruald\Broker\Broker;
-
use Mockery;
+use Nasqueron\Notifications\Config\Services\Service;
-class TestCase extends \Illuminate\Foundation\Testing\TestCase
-{
- /**
- * The base URL to use while testing the application.
- *
- * @var string
- */
- protected $baseUrl = 'http://localhost';
-
- /**
- * Creates the application.
- *
- * @return \Illuminate\Foundation\Application
- */
- public function createApplication()
- {
- $app = require __DIR__.'/../bootstrap/app.php';
-
- $app->make(Kernel::class)->bootstrap();
-
- return $app;
- }
-
- ///
- /// Helpers to mock application services
- ///
-
- /**
- * Mocks the events dispatcher
- */
- public function disableEvents () {
- // Disables events
- // This allows to test a single component and not all the application
- $mock = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
-
- $mock->shouldReceive('fire');
- $mock->shouldReceive('listen');
-
- $this->app->instance('events', $mock);
- }
-
- /**
- * Mocks the broker
- */
- public function disableBroker () {
- $broker = new BlackholeBroker();
- $broker->acceptAllMethodCalls(); // allows to be used as a mock
- $this->app->instance('broker', $broker);
- }
-
- /**
- * Mocks the broker, throwing an exception when sendMessage is called.
- */
- public function mockNotOperationalBroker () {
- $mock = Mockery::mock('Keruald\Broker\Broker');
- $mock->shouldReceive('connect');
- $mock->shouldReceive('setExchangeTarget->routeTo->sendMessage')
- ->andThrow(new \RuntimeException);
-
- $this->app->instance('broker', $mock);
- }
-
- /**
- * Mocks the Phabricator API
- *
- * @return \Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory The mock
- */
- protected function mockPhabricatorAPI () {
- // Inject into our container a mock of PhabricatorAPI
- $mock = Mockery::mock('Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory');
- $this->app->instance('phabricator-api', $mock);
-
- return $mock;
- }
-
- private function mockPhabricatorAPIProjectsQueryReply () {
- $json = file_get_contents('tests/data/PhabricatorProjetsQueryReply.json');
- return json_decode($json);
- }
-
- /**
- * Mocks the Phabricator API
- */
- protected function mockPhabricatorAPIForProjectsMap () {
- $mock = $this->mockPhabricatorAPI();
-
- $reply = $this->mockPhabricatorAPIProjectsQueryReply();
- $mock->shouldReceive('getForProject->call')->andReturn($reply);
- }
-
- ///
- /// Helper methods to mock services
- ///
-
- protected function mockServices () {
- // Inject into our container a mock of Services
- $mock = Mockery::mock('Nasqueron\Notifications\Config\Services\Services');
- $this->app->instance('services', $mock);
-
- return $mock;
- }
-
- protected function mockService ($gate = 'Storm') {
- $service = new Service;
- $service->gate = $gate;
- $service->door = 'Acme';
- $service->instance = "http://www.perdu.com";
-
- return $service;
- }
-
- ///
- /// Helpers to post data to gates
- ///
-
- /**
- * Visits the given URI with a JSON request.
- *
- * @param string $uri
- * @param mixed $data
- * @param string $method
- * @param array $headers
- * @return $this
- */
- public function sendJsonPayload ($uri, $data, $method = 'POST', array $headers = []) {
- $content = json_encode($data);
- $headers = array_merge([
- 'CONTENT_TYPE' => 'application/json',
- 'Accept' => 'application/json',
- ], $headers);
- return $this->sendPayload($uri, $content, $method, $headers);
- }
-
- /**
- * Visits the given URI with a raw request.
- *
- * @param string $uri
- * @param string $content
- * @param string $method
- * @param array $headers
- * @return $this
- */
- public function sendPayload ($uri, $content, $method = 'POST', array $headers = []) {
- $headers = array_merge([
- 'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
- ], $headers);
-
- $this->call(
- $method, $uri, [], [], [], $this->transformHeadersToServerVars($headers), $content
- );
-
- return $this;
- }
+class TestCase extends \Illuminate\Foundation\Testing\TestCase {
+ /**
+ * The base URL to use while testing the application.
+ *
+ * @var string
+ */
+ protected $baseUrl = 'http://localhost';
+
+ /**
+ * Creates the application.
+ *
+ * @return \Illuminate\Foundation\Application
+ */
+ public function createApplication() {
+ $app = require __DIR__ . '/../bootstrap/app.php';
+
+ $app->make( Kernel::class )->bootstrap();
+
+ return $app;
+ }
+
+ ///
+ /// Helpers to mock application services
+ ///
+
+ /**
+ * Mocks the events dispatcher
+ */
+ public function disableEvents() {
+ // Disables events
+ // This allows to test a single component and not all the application
+ $mock = Mockery::mock( 'Illuminate\Contracts\Events\Dispatcher' );
+
+ $mock->shouldReceive( 'fire' );
+ $mock->shouldReceive( 'listen' );
+
+ $this->app->instance( 'events', $mock );
+ }
+
+ /**
+ * Mocks the broker
+ */
+ public function disableBroker() {
+ $broker = new BlackholeBroker();
+ $broker->acceptAllMethodCalls(); // allows to be used as a mock
+ $this->app->instance( 'broker', $broker );
+ }
+
+ /**
+ * Mocks the broker, throwing an exception when sendMessage is called.
+ */
+ public function mockNotOperationalBroker() {
+ $mock = Mockery::mock( 'Keruald\Broker\Broker' );
+ $mock->shouldReceive( 'connect' );
+ $mock->shouldReceive( 'setExchangeTarget->routeTo->sendMessage' )
+ ->andThrow( new \RuntimeException );
+
+ $this->app->instance( 'broker', $mock );
+ }
+
+ /**
+ * Mocks the Phabricator API
+ *
+ * @return \Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory The mock
+ */
+ protected function mockPhabricatorAPI() {
+ // Inject into our container a mock of PhabricatorAPI
+ $mock = Mockery::mock( 'Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory' );
+ $this->app->instance( 'phabricator-api', $mock );
+
+ return $mock;
+ }
+
+ private function mockPhabricatorAPIProjectsQueryReply() {
+ $json = file_get_contents( 'tests/data/PhabricatorProjetsQueryReply.json' );
+ return json_decode( $json );
+ }
+
+ /**
+ * Mocks the Phabricator API
+ */
+ protected function mockPhabricatorAPIForProjectsMap() {
+ $mock = $this->mockPhabricatorAPI();
+
+ $reply = $this->mockPhabricatorAPIProjectsQueryReply();
+ $mock->shouldReceive( 'getForProject->call' )->andReturn( $reply );
+ }
+
+ ///
+ /// Helper methods to mock services
+ ///
+
+ protected function mockServices() {
+ // Inject into our container a mock of Services
+ $mock = Mockery::mock( 'Nasqueron\Notifications\Config\Services\Services' );
+ $this->app->instance( 'services', $mock );
+
+ return $mock;
+ }
+
+ protected function mockService( $gate = 'Storm' ) {
+ $service = new Service;
+ $service->gate = $gate;
+ $service->door = 'Acme';
+ $service->instance = "http://www.perdu.com";
+
+ return $service;
+ }
+
+ ///
+ /// Helpers to post data to gates
+ ///
+
+ /**
+ * Visits the given URI with a JSON request.
+ *
+ * @param mixed $data
+ * @return $this
+ */
+ public function sendJsonPayload( string $uri, $data, string $method = 'POST', array $headers = [] ) {
+ $content = json_encode( $data );
+ $headers = array_merge( [
+ 'CONTENT_TYPE' => 'application/json',
+ 'Accept' => 'application/json',
+ ], $headers );
+ return $this->sendPayload( $uri, $content, $method, $headers );
+ }
+
+ /**
+ * Visits the given URI with a raw request.
+ *
+ * @return $this
+ */
+ public function sendPayload( string $uri, string $content, string $method = 'POST', array $headers = [] ) {
+ $headers = array_merge( [
+ 'CONTENT_LENGTH' => mb_strlen( $content, '8bit' ),
+ ], $headers );
+
+ $this->call(
+ $method, $uri, [], [], [], $this->transformHeadersToServerVars( $headers ), $content
+ );
+
+ return $this;
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 03:41 (15 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2256572
Default Alt Text
D2674.id6760.largetrue.diff (602 KB)

Event Timeline