Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
* Remove docblocks that are no longer needed
As we have types already added to the code
then the docblocks don't add anything
and actually make it harder to maintain

* Add CS formatting rules
Make sure all classes are consistent
by having a new line after the opening tag.
At the minute there's a mixture of the two.
Removed unused imports

* Add phpunit cache to gitignore
  • Loading branch information
maxbaldanza committed May 23, 2024
1 parent 911e2a8 commit d3ee826
Show file tree
Hide file tree
Showing 56 changed files with 100 additions and 523 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ GTAGS
.idea
/tmp
.php-cs-fixer.cache
.phpunit.result.cache
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
return $config->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'no_unused_imports' => true,
])
->setFinder($finder)
;
1 change: 1 addition & 0 deletions examples/common.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use \Ackintosh\Ganesha;
use \Ackintosh\Ganesha\Builder;

Expand Down
1 change: 1 addition & 0 deletions examples/server/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require_once dirname(__DIR__) . '/common.php';

if (trim(file_get_contents(SERVER_STATE_DATA)) === SERVER_STATE_ABNORMAL) {
Expand Down
1 change: 1 addition & 0 deletions examples/server/redirect.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

const DEFAULT_REDIRECTS = 3;

$current = $_GET['current'] ?? 0;
Expand Down
1 change: 1 addition & 0 deletions examples/server/timeout.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php

sleep(10);
48 changes: 10 additions & 38 deletions src/Ganesha.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh;

use Ackintosh\Ganesha\Exception\StorageException;
Expand Down Expand Up @@ -48,23 +49,15 @@ class Ganesha
*/
private static $disabled = false;

/**
* Ganesha constructor.
*
* @param StrategyInterface $strategy
*/
public function __construct($strategy)
public function __construct(StrategyInterface $strategy)
{
$this->strategy = $strategy;
}

/**
* records failure
*
* @param string $service
* @return void
* Records failure
*/
public function failure($service): void
public function failure(string $service): void
{
try {
if ($this->strategy->recordFailure($service) === self::STATUS_TRIPPED) {
Expand All @@ -76,12 +69,9 @@ public function failure($service): void
}

/**
* records success
*
* @param string $service
* @return void
* Records success
*/
public function success($service): void
public function success(string $service): void
{
try {
if ($this->strategy->recordSuccess($service) === self::STATUS_CALMED_DOWN) {
Expand All @@ -92,11 +82,7 @@ public function success($service): void
}
}

/**
* @param string $service
* @return bool
*/
public function isAvailable($service): bool
public function isAvailable(string $service): bool
{
if (self::$disabled) {
return true;
Expand All @@ -112,21 +98,13 @@ public function isAvailable($service): bool
}

/**
* @param callable $callable
* @psalm-param callable(self::EVENT_*, string, string): void $callable
* @return void
*/
public function subscribe(callable $callable): void
{
$this->subscribers[] = $callable;
}

/**
* @param string $event
* @param string $service
* @param string $message
* @return void
*/
private function notify(string $event, string $service, string $message): void
{
foreach ($this->subscribers as $s) {
Expand All @@ -135,29 +113,23 @@ private function notify(string $event, string $service, string $message): void
}

/**
* disable
*
* @return void
* Disable
*/
public static function disable(): void
{
self::$disabled = true;
}

/**
* enable
*
* @return void
* Enable
*/
public static function enable(): void
{
self::$disabled = false;
}

/**
* resets all counts
*
* @return void
* Resets all counts
*/
public function reset(): void
{
Expand Down
9 changes: 1 addition & 8 deletions src/Ganesha/Builder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha\Strategy;
namespace Ackintosh\Ganesha;

/**
* A front end of the strategy specific builders
Expand All @@ -10,17 +9,11 @@
*/
class Builder
{
/**
* @return Strategy\Rate\Builder
*/
public static function withRateStrategy(): Strategy\Rate\Builder
{
return new Strategy\Rate\Builder();
}

/**
* @return Strategy\Count\Builder
*/
public static function withCountStrategy(): Strategy\Count\Builder
{
return new Strategy\Count\Builder();
Expand Down
10 changes: 3 additions & 7 deletions src/Ganesha/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha\Storage\AdapterInterface;
Expand All @@ -16,13 +17,9 @@ class Configuration
const INTERVAL_TO_HALF_OPEN = 'intervalToHalfOpen';
const STORAGE_KEYS = 'storageKeys';

/**
* @var array
*/
private $params;
private array $params;

/** @param array $params */
public function __construct($params)
public function __construct(array $params)
{
if (!isset($params[self::STORAGE_KEYS])) {
$params[self::STORAGE_KEYS] = new StorageKeys();
Expand Down Expand Up @@ -61,7 +58,6 @@ public function storageKeys(): StorageKeysInterface
}

/**
* @param array $params
* @throws \InvalidArgumentException
*/
public static function validate(array $params): void
Expand Down
6 changes: 1 addition & 5 deletions src/Ganesha/Context.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface;
Expand Down Expand Up @@ -34,11 +35,6 @@ class Context
*/
private $configuration;

/**
* @param string $strategyClass
* @param AdapterInterface $adapter
* @param Configuration $configuration
*/
public function __construct(string $strategyClass, AdapterInterface $adapter, Configuration $configuration)
{
$this->strategy = $this->determineStrategyContext($strategyClass, $adapter);
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/Exception/RejectedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\Exception;

class RejectedException extends \RuntimeException
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/Exception/StorageException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\Exception;

class StorageException extends \RuntimeException
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/GaneshaHttpClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha;
Expand Down
5 changes: 1 addition & 4 deletions src/Ganesha/GuzzleMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha;
Expand Down Expand Up @@ -60,10 +61,6 @@ public function __construct(
}
}

/**
* @param callable $handler
* @return \Closure
*/
public function __invoke(callable $handler): \Closure
{
return function (RequestInterface $request, array $options) use ($handler) {
Expand Down
8 changes: 2 additions & 6 deletions src/Ganesha/GuzzleMiddleware/ServiceNameExtractor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\GuzzleMiddleware;

use Psr\Http\Message\RequestInterface;
Expand All @@ -15,12 +16,7 @@ class ServiceNameExtractor implements ServiceNameExtractorInterface
*/
const HEADER_NAME = 'X-Ganesha-Service-Name';

/**
* @param RequestInterface $request
* @param array $requestOptions
* @return string
*/
public function extract(RequestInterface $request, array $requestOptions)
public function extract(RequestInterface $request, array $requestOptions): string
{
if (array_key_exists(self::OPTION_KEY, $requestOptions)) {
return $requestOptions[self::OPTION_KEY];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<?php

namespace Ackintosh\Ganesha\GuzzleMiddleware;

use Psr\Http\Message\RequestInterface;

interface ServiceNameExtractorInterface
{
/**
* @param RequestInterface $request
* @param array $requestOptions
* @return string
*/
public function extract(RequestInterface $request, array $requestOptions);
public function extract(RequestInterface $request, array $requestOptions): string;
}
1 change: 1 addition & 0 deletions src/Ganesha/HttpClient/FailureDetectorInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\HttpClient;

use Symfony\Contracts\HttpClient\ResponseInterface;
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/HttpClient/HostTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\HttpClient;

use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/HttpClient/RestFailureDetector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\HttpClient;

use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/HttpClient/ServiceNameExtractor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\HttpClient;

final class ServiceNameExtractor implements ServiceNameExtractorInterface
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/HttpClient/ServiceNameExtractorInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\HttpClient;

interface ServiceNameExtractorInterface
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/HttpClient/TransportFailureDetector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ackintosh\Ganesha\HttpClient;

use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
Expand Down
Loading

0 comments on commit d3ee826

Please sign in to comment.