Skip to content

Commit

Permalink
fix PHP 8 deprecations and typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Lambert committed Aug 14, 2024
1 parent 95b494c commit c018e30
Show file tree
Hide file tree
Showing 29 changed files with 122 additions and 155 deletions.
20 changes: 4 additions & 16 deletions Command/DebugFlagsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@

class DebugFlagsCommand extends Command
{
/**
* @var Toggle
*/
private $toggle;

/**
* @var Toggle\ConditionBag
*/
private $conditionBag;

public function __construct(Toggle $toggle, Toggle\ConditionBag $conditionBag)
public function __construct(private readonly Toggle $toggle, private readonly Toggle\ConditionBag $conditionBag)
{
parent::__construct();
$this->toggle = $toggle;
$this->conditionBag = $conditionBag;
}

protected function configure()
protected function configure(): void
{
$this
->setName('dzunke:feature_flags:debug')
Expand All @@ -50,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table->setStyle('borderless');
$table->setHeaders(['name', 'class']);
foreach ($this->conditionBag as $name => $condition) {
$table->addRow([$name, get_class($condition)]);
$table->addRow([$name, $condition::class]);
}
$table->render();

Expand All @@ -67,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

private function renderFlagsTable(OutputInterface $output)
private function renderFlagsTable(OutputInterface $output): void
{
$flags = $this->toggle->getFlags();
if (empty($flags)) {
Expand Down
6 changes: 3 additions & 3 deletions Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Context
* @param mixed $value
* @return $this
*/
public function set($name, $value)
public function set($name, $value): self
{
$this->context[(string)$name] = $value;

Expand All @@ -34,15 +34,15 @@ public function get($name)
/**
* @return array
*/
public function all()
public function all(): array
{
return $this->context;
}

/**
* @return $this
*/
public function clear()
public function clear(): self
{
$this->context = [];

Expand Down
2 changes: 1 addition & 1 deletion DZunkeFeatureFlagsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class DZunkeFeatureFlagsBundle extends Bundle
{

public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
10 changes: 5 additions & 5 deletions DependencyInjection/Compiler/Conditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Conditions implements CompilerPassInterface
/**
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (true !== $container->getParameterBag()->has('d_zunke_feature_flags.config')) {
throw new \RuntimeException('No parameters with name \'d_zunke_feature_flags.config\' could be found');
Expand All @@ -28,7 +28,7 @@ public function process(ContainerBuilder $container)
* @param array $config
* @param ContainerBuilder $container
*/
private function configureToggle(array $config, ContainerBuilder $container)
private function configureToggle(array $config, ContainerBuilder $container): void
{
$definition = $container->getDefinition('dz.feature_flags.toggle');
$definition->addMethodCall('setDefaultState', [$config['default']]);
Expand All @@ -52,7 +52,7 @@ private function configureToggle(array $config, ContainerBuilder $container)
/**
* @param ContainerBuilder $container
*/
private function fillConditionsBag(ContainerBuilder $container)
private function fillConditionsBag(ContainerBuilder $container): void
{
$taggedConditions = $container->findTaggedServiceIds('dz.feature_flags.toggle.condition');

Expand All @@ -76,7 +76,7 @@ private function fillConditionsBag(ContainerBuilder $container)
*
* @return Definition
*/
private function createFlagDefinition($name, Reference $reference, $default)
private function createFlagDefinition($name, Reference $reference, $default): Definition
{
return new Definition(
Flag::class,
Expand All @@ -92,7 +92,7 @@ private function createFlagDefinition($name, Reference $reference, $default)
* @param Definition $flag
* @param array $config
*/
private function processFlagConditions(Definition $flag, array $config)
private function processFlagConditions(Definition $flag, array $config): void
{
foreach($config as $condition => $optionalValues) {
$flag->addMethodCall(
Expand Down
7 changes: 4 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DZunke\FeatureFlagsBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -12,7 +13,7 @@ class Configuration implements ConfigurationInterface
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('d_zunke_feature_flags');
$rootNode = $treeBuilder->getRootNode();
Expand All @@ -30,9 +31,9 @@ public function getConfigTreeBuilder()
}

/**
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
* @return ArrayNodeDefinition|NodeDefinition
*/
private function addFlags()
private function addFlags(): ArrayNodeDefinition|NodeDefinition
{
$treeBuilder = new TreeBuilder('flags');
$node = $treeBuilder->getRootNode();
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/DZunkeFeatureFlagsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DZunkeFeatureFlagsExtension extends Extension
* @param array $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
Expand Down
11 changes: 2 additions & 9 deletions EventListener/ContextCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@

class ContextCreator
{
/**
* @var Context
*/
private $context;

/**
* @param Context $context
*/
public function __construct(Context $context)
public function __construct(private readonly Context $context)
{
$this->context = $context;
}

/**
* @param RequestEvent $event
*/
public function onKernelRequest(RequestEvent $event)
public function onKernelRequest(RequestEvent $event): void
{
$this->context->set('client_ip', $event->getRequest()->getClientIp());
$this->context->set('hostname', $event->getRequest()->getHost());
}

}
8 changes: 4 additions & 4 deletions Tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
class ContextTest extends TestCase
{

public function testGetAndSet()
public function testGetAndSet(): void
{
$sut = new Context();

$this->assertInstanceOf(Context::class, $sut->set('first', 'value'));
$this->assertSame('value', $sut->get('first'));
}

public function testAll()
public function testAll(): void
{
$sut = new Context();
$sut->set('first', 'value');
Expand All @@ -25,7 +25,7 @@ public function testAll()
$this->assertSame(1, count($sut->all()));
}

public function testClear()
public function testClear(): void
{
$sut = new Context();
$sut->set('first', 'value');
Expand All @@ -36,4 +36,4 @@ public function testClear()
$this->assertNull($sut->get('second'));
}

}
}
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class ConfigurationTest extends TestCase
{
public function testDefaultConfigurationCouldBeLoaded()
public function testDefaultConfigurationCouldBeLoaded(): void
{
$container = new ContainerBuilder();
$extension = new DZunkeFeatureFlagsExtension();
Expand All @@ -21,4 +21,4 @@ public function testDefaultConfigurationCouldBeLoaded()
$config
);
}
}
}
6 changes: 3 additions & 3 deletions Tests/Toggle/ConditionBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
class ConditionBagTest extends TestCase
{

public function testItImplementsClasses()
public function testItImplementsClasses(): void
{
$sut = new ConditionBag();
$this->assertInstanceOf(IteratorAggregate::class, $sut);
$this->assertInstanceOf(Countable::class, $sut);
}

public function testConditionBag()
public function testConditionBag(): void
{
$conditionMock = $this->createMock(ConditionInterface::class);
$conditionMock->method('__toString')->willReturn('test_condition');
Expand All @@ -39,4 +39,4 @@ public function testConditionBag()
$this->assertCount(0, $sut->remove('test_condition'));
}

}
}
24 changes: 12 additions & 12 deletions Tests/Toggle/Conditions/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ class DateTest extends TestCase
/**
* @var string
*/
const CURRENT_DATE = "2016-09-02T00:00:00Z";
public const CURRENT_DATE = "2016-09-02T00:00:00Z";

/**
* @var string
*/
const FUTURE_DATE1 = "2020-12-25T12:00:00Z";
public const FUTURE_DATE1 = "2020-12-25T12:00:00Z";

/**
* @var string
*/
const FUTURE_DATE2 = "2017-0-0T00:00:00Z";
public const FUTURE_DATE2 = "2017-0-0T00:00:00Z";

/**
* @var string
*/
const PAST_DATE1 = "1970-01-01T00:00:00Z";
public const PAST_DATE1 = "1970-01-01T00:00:00Z";

/**
* @var string
*/
const PAST_DATE2 = "2014-01-01T00:00:00Z";
public const PAST_DATE2 = "2014-01-01T00:00:00Z";

/**
* Returns an instance of Date with a known "current" date.
*
* @return Date
*/
public function getInstanceOfDate()
public function getInstanceOfDate(): Date
{
$contextMock = $this->createMock(Context::class);

Expand All @@ -56,22 +56,22 @@ public function getInstanceOfDate()
return $date;
}

public function testItExtendsCorrectly()
public function testItExtendsCorrectly(): void
{
$sut = $this->getInstanceOfDate();

$this->assertInstanceOf(AbstractCondition::class, $sut);
$this->assertInstanceOf(ConditionInterface::class, $sut);
}

public function testItReturnsTrueWithoutStartOrEndDate()
public function testItReturnsTrueWithoutStartOrEndDate(): void
{
$config = [];
$sut = $this->getInstanceOfDate();
$this->assertTrue($sut->validate($config));
}

public function testItReturnsTrueWithPastStartDate()
public function testItReturnsTrueWithPastStartDate(): void
{
$sut = $this->getInstanceOfDate();
$this->assertTrue($sut->validate([
Expand All @@ -88,7 +88,7 @@ public function testItReturnsTrueWithPastStartDate()
]));
}

public function testItReturnsTrueWithFutureEndDate()
public function testItReturnsTrueWithFutureEndDate(): void
{
$sut = $this->getInstanceOfDate();
$this->assertTrue($sut->validate([
Expand All @@ -105,7 +105,7 @@ public function testItReturnsTrueWithFutureEndDate()
]));
}

public function testItReturnsTrueWhenBetweenPastStartAndFutureEndDate()
public function testItReturnsTrueWhenBetweenPastStartAndFutureEndDate(): void
{
$sut = $this->getInstanceOfDate();
$this->assertTrue($sut->validate([
Expand All @@ -126,7 +126,7 @@ public function testItReturnsTrueWhenBetweenPastStartAndFutureEndDate()
]));
}

public function testToString()
public function testToString(): void
{
$sut = $this->getInstanceOfDate();

Expand Down
Loading

0 comments on commit c018e30

Please sign in to comment.