Skip to content

Commit 829ef9e

Browse files
authored
Merge pull request #6 from dbalabka/code-cleanup
Code cleanup
2 parents 7453456 + f5340dc commit 829ef9e

29 files changed

+137
-91
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ and [Python Enums](https://docs.python.org/3/library/enum.html).
1919
A basic way to declare a named Enumeration class:
2020
```php
2121
<?php
22-
use Dbalabka\Enumeration;
22+
use Dbalabka\Enumeration\Enumeration;
2323

2424
final class Action extends Enumeration
2525
{
@@ -126,14 +126,16 @@ multiple Enumeration classes.
126126
> On the other hand, it makes sense to allow sharing some common behavior between a group of enumerations...
127127
> (from [Python Enum documentation](https://docs.python.org/3/library/enum.html#restricted-enum-subclassing))
128128
2. Constructor should always be declared as non-public (`private` or `protected`) to avoid unwanted class instantiation.
129-
3. Implementation is based on assumption that all class static properties are elements of Enum. If there is a need to declare
130-
any static property that isn't an Enum element then you should override the `\Dbalabka\Enumeration::getStaticVars()` method.
131-
4. The method `Dbalabka\Enumeration::initialize()` should be called after each Enumeration class declaration. Please use the
129+
3. Implementation is based on assumption that all class static properties are elements of Enum. <!-- If there is a need to declare
130+
any static property that isn't an Enum element then you should override the `\Dbalabka\Enumeration\Enumeration::$notEnumVars` method. -->
131+
4. The method `Dbalabka\Enumeration\Enumeration::initialize()` should be called after each Enumeration class declaration. Please use the
132132
[vladimmi/construct-static](https://github.com/vladimmi/construct-static) custom loader to avoid boilerplate code.
133133

134134
## Usage
135135
```php
136136
<?php
137+
use Dbalabka\Enumeration\Examples\Enum\Action;
138+
137139
$viewAction = Action::$view;
138140

139141
// it is possible to compare Enum elements
@@ -147,6 +149,7 @@ assert($editAction === Action::$edit);
147149
foreach (Action::values() as $name => $action) {
148150
assert($action instanceof Action);
149151
assert($name === (string) $action);
152+
assert($name === $action->name());
150153
}
151154
```
152155

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
},
2424
"autoload": {
2525
"psr-4": {
26-
"Dbalabka\\": "src"
26+
"Dbalabka\\Enumeration\\": "src"
2727
}
2828
},
2929
"autoload-dev": {
3030
"psr-4": {
31-
"Dbalabka\\Examples\\": "examples",
32-
"Dbalabka\\Tests\\": "tests"
31+
"Dbalabka\\Enumeration\\Examples\\": "examples",
32+
"Dbalabka\\Enumeration\\Tests\\": "tests"
3333
}
3434
}
3535
}

examples/Enum/Action.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Dbalabka\Examples\Enum;
4+
namespace Dbalabka\Enumeration\Examples\Enum;
55

6-
use Dbalabka\Enumeration;
6+
use Dbalabka\Enumeration\Enumeration;
77

88
final class Action extends Enumeration
99
{

examples/Enum/CardType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Dbalabka\Examples\Enum;
4+
namespace Dbalabka\Enumeration\Examples\Enum;
55

6-
use Dbalabka\Enumeration;
6+
use Dbalabka\Enumeration\Enumeration;
77

88
final class CardType extends Enumeration
99
{

examples/Enum/Color.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Dbalabka\Examples\Enum;
4+
namespace Dbalabka\Enumeration\Examples\Enum;
55

6-
use Dbalabka\Enumeration;
6+
use Dbalabka\Enumeration\Enumeration;
77

88
final class Color extends Enumeration
99
{

examples/Enum/Day.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Dbalabka\Examples\Enum;
4+
namespace Dbalabka\Enumeration\Examples\Enum;
55

6-
use Dbalabka\Enumeration;
6+
use Dbalabka\Enumeration\Enumeration;
77

88
final class Day extends Enumeration
99
{

examples/Enum/Flag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Dbalabka\Examples\Enum;
4+
namespace Dbalabka\Enumeration\Examples\Enum;
55

6-
use Dbalabka\Enumeration;
6+
use Dbalabka\Enumeration\Enumeration;
77

88
final class Flag extends Enumeration
99
{

examples/Enum/Planet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Dbalabka\Examples\Enum;
4+
namespace Dbalabka\Enumeration\Examples\Enum;
55

6-
use Dbalabka\Enumeration;
6+
use Dbalabka\Enumeration\Enumeration;
77

88
final class Planet extends Enumeration
99
{

examples/card_type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
use Dbalabka\Examples\Enum\CardType;
4+
use Dbalabka\Enumeration\Examples\Enum\CardType;
55

66
require_once(__DIR__ . '/../vendor/autoload.php');
77

examples/class_static_construct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
use Dbalabka\Examples\Enum\Color;
4+
use Dbalabka\Enumeration\Examples\Enum\Color;
55

66
$composer = require_once(__DIR__ . '/../vendor/autoload.php');
77
$loader = new ConstructStatic\Loader($composer);

0 commit comments

Comments
 (0)