Skip to content

Commit

Permalink
Merge pull request #48 from zumba/drop-php-7
Browse files Browse the repository at this point in the history
Dropped support to PHP 7.x
  • Loading branch information
jrbasso authored Apr 3, 2024
2 parents 229a424 + 1640aa6 commit 96b5bd9
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 597 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

strategy:
matrix:
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php-version: ['8.0', '8.1', '8.2', '8.3']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}
],
"require": {
"php": ">=7.2",
"php": "^8.0",
"psr/log": "^1.0 | ^2.0 | ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.5",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
Expand Down
11 changes: 6 additions & 5 deletions src/Behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Behavior implements BehaviorInterface
*
* @var string
*/
protected $slug;
protected string $slug;

/**
* The strategy to be executed.
Expand All @@ -28,7 +28,7 @@ class Behavior implements BehaviorInterface
* @param string $slug
* @param callable $strategy
*/
public function __construct($slug, callable $strategy)
public function __construct(string $slug, callable $strategy)
{
$this->slug = $slug;
$this->strategy = $strategy;
Expand All @@ -43,14 +43,15 @@ public function __construct($slug, callable $strategy)
*
* @see \Zumba\Swivel\BehaviorInterface
*/
public function execute(array $args = [])
public function execute(array $args = []): mixed
{
$slug = $this->slug;
if ($this->logger) {
$this->logger->debug('Swivel - Executing behavior.', compact('slug', 'args'));
}

return call_user_func_array($this->strategy, $args);
$method = $this->strategy;
return $method(...$args);
}

/**
Expand All @@ -60,7 +61,7 @@ public function execute(array $args = [])
*
* @see \Zumba\Swivel\BehaviorInterface
*/
public function getSlug()
public function getSlug(): string
{
return $this->slug;
}
Expand Down
4 changes: 2 additions & 2 deletions src/BehaviorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ interface BehaviorInterface extends \Psr\Log\LoggerAwareInterface
*
* @return mixed
*/
public function execute(array $args = []);
public function execute(array $args = []): mixed;

/**
* Get the behavior's slug.
*
* @return string
*/
public function getSlug();
public function getSlug(): string;
}
19 changes: 9 additions & 10 deletions src/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Zumba\Swivel;

use Zumba\Swivel\MapInterface;
use Psr\Log\LoggerInterface;
use Zumba\Swivel\Logging\NullLogger;

Expand Down Expand Up @@ -30,14 +29,14 @@ class Bucket implements BucketInterface
*
* @var Zumba\Swivel\MapInterface
*/
protected $featureMap;
protected MapInterface $featureMap;

/**
* The user's index.
*
* @var int Binary
*/
protected $index;
protected int $index;

/**
* Callback to handle a missing slug from Map
Expand All @@ -61,9 +60,8 @@ public function __construct(
) {
$this->setLogger($logger ?: new NullLogger());
$this->featureMap = $featureMap;
$this->index = $index === null ? $this->randomIndex() : $index;
$this->callback = !is_null($callback) ? $callback : function () {
};
$this->index = $index ?: $this->randomIndex();
$this->callback = $callback ?: (fn() => null);
}

/**
Expand All @@ -75,12 +73,13 @@ public function __construct(
*
* @see \Zumba\Swivel\BucketInterface
*/
public function enabled(BehaviorInterface $behavior)
public function enabled(BehaviorInterface $behavior): bool
{
$slug = $behavior->getSlug();

if (!$this->featureMap->slugExists($slug)) {
call_user_func($this->callback, $slug);
$callback = $this->callback;
$callback($slug);
}
return $this->featureMap->enabled($slug, $this->index);
}
Expand All @@ -92,7 +91,7 @@ public function enabled(BehaviorInterface $behavior)
*
* @return int
*/
public function getIndex()
public function getIndex(): int
{
return $this->index;
}
Expand All @@ -102,7 +101,7 @@ public function getIndex()
*
* @return int
*/
protected function randomIndex()
protected function randomIndex(): int
{
return mt_rand(1, 10);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BucketInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface BucketInterface extends \Psr\Log\LoggerAwareInterface
*
* @return bool
*/
public function enabled(BehaviorInterface $behavior);
public function enabled(BehaviorInterface $behavior): bool;

/**
* Get the bucket index.
Expand All @@ -20,5 +20,5 @@ public function enabled(BehaviorInterface $behavior);
*
* @return int
*/
public function getIndex();
public function getIndex(): int;
}
Loading

0 comments on commit 96b5bd9

Please sign in to comment.