Skip to content

Commit 6b7819a

Browse files
committed
style: add BrainbitsCodingStandard and phpcs
1 parent e1d37ba commit 6b7819a

30 files changed

Lines changed: 109 additions & 81 deletions

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ jobs:
4444

4545
- name: "Unit tests"
4646
run: "vendor/bin/phpunit"
47+
48+
- name: "Coding style"
49+
run: "vendor/bin/phpcs --report=summary"

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"symfony/http-foundation": ">=4.4",
2020
"symfony/security-core": ">=4.4",
2121
"phpspec/prophecy": "^1.14",
22-
"phpspec/prophecy-phpunit": "^2.0.1"
22+
"phpspec/prophecy-phpunit": "^2.0.1",
23+
"squizlabs/php_codesniffer": "^3.6",
24+
"brainbits/phpcs-standard": "^5.0"
2325
},
2426
"suggest": {
2527
"symfony/http-foundation": "If you want to use the SymfonySessionOwnerFactory",

phpcs.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
<file extension="php">src/</file>
4+
<arg name="basepath" value="." />
5+
<arg name="colors" />
6+
<rule ref="Brainbits">
7+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix" />
8+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix" />
9+
</rule>
10+
</ruleset>

src/Block.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.
@@ -16,16 +16,17 @@
1616
use Brainbits\Blocking\Identity\IdentityInterface;
1717
use Brainbits\Blocking\Owner\OwnerInterface;
1818
use DateTimeImmutable;
19+
use DateTimeInterface;
1920

2021
/**
2122
* Standard block.
2223
*/
2324
class Block implements BlockInterface
2425
{
25-
private $identifier;
26-
private $owner;
27-
private $createdAt;
28-
private $updatedAt;
26+
private IdentityInterface $identifier;
27+
private OwnerInterface $owner;
28+
private DateTimeInterface $createdAt;
29+
private DateTimeInterface $updatedAt;
2930

3031
public function __construct(IdentityInterface $identifier, OwnerInterface $owner, DateTimeImmutable $createdAt)
3132
{

src/BlockInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.

src/BlockableInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.
@@ -22,8 +22,6 @@ interface BlockableInterface
2222
{
2323
/**
2424
* Return block identifier
25-
*
26-
* @return IdentityInterface
2725
*/
28-
public function getBlockIdentifier();
26+
public function getBlockIdentifier(): IdentityInterface;
2927
}

src/Blocker.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.
@@ -25,12 +25,15 @@
2525
*/
2626
class Blocker
2727
{
28-
private $storage;
29-
private $ownerFactory;
30-
private $validator;
31-
32-
public function __construct(StorageInterface $adapter, OwnerFactoryInterface $ownerFactory, ValidatorInterface $validator)
33-
{
28+
private StorageInterface $storage;
29+
private OwnerFactoryInterface $ownerFactory;
30+
private ValidatorInterface $validator;
31+
32+
public function __construct(
33+
StorageInterface $adapter,
34+
OwnerFactoryInterface $ownerFactory,
35+
ValidatorInterface $validator
36+
) {
3437
$this->storage = $adapter;
3538
$this->ownerFactory = $ownerFactory;
3639
$this->validator = $validator;
@@ -56,6 +59,7 @@ public function tryBlock(IdentityInterface $identifier): ?BlockInterface
5659
if (!$block->isOwnedBy($owner)) {
5760
return null;
5861
}
62+
5963
$this->storage->touch($block);
6064

6165
return $block;
@@ -71,7 +75,7 @@ public function tryBlock(IdentityInterface $identifier): ?BlockInterface
7175
public function unblock(IdentityInterface $identifier): ?BlockInterface
7276
{
7377
$block = $this->getBlock($identifier);
74-
if (null === $block) {
78+
if ($block === null) {
7579
return null;
7680
}
7781

src/Exception/BlockFailedException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.
@@ -15,13 +15,15 @@
1515

1616
use Brainbits\Blocking\Identity\IdentityInterface;
1717

18+
use function sprintf;
19+
1820
/**
1921
* Block failed exception.
2022
*/
2123
class BlockFailedException extends RuntimeException
2224
{
2325
public static function createAlreadyBlocked(IdentityInterface $identifier): self
2426
{
25-
return new self("Identifier $identifier is already blocked.");
27+
return new self(sprintf('Identifier %s is already blocked.', $identifier));
2628
}
2729
}

src/Exception/DirectoryNotWritableException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.
@@ -13,13 +13,15 @@
1313

1414
namespace Brainbits\Blocking\Exception;
1515

16+
use function sprintf;
17+
1618
/**
1719
* Directory not writable exception.
1820
*/
1921
class DirectoryNotWritableException extends RuntimeException
2022
{
2123
public static function create(string $dirname): self
2224
{
23-
return new self("Directory $dirname not writable.");
25+
return new self(sprintf('Directory %s not writable.', $dirname));
2426
}
2527
}

src/Exception/ExceptionInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
/*
66
* This file is part of the brainbits blocking package.
@@ -13,9 +13,11 @@
1313

1414
namespace Brainbits\Blocking\Exception;
1515

16+
use Throwable;
17+
1618
/**
1719
* Exception interface.
1820
*/
19-
interface ExceptionInterface extends \Throwable
21+
interface ExceptionInterface extends Throwable
2022
{
2123
}

0 commit comments

Comments
 (0)