Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jan Kuchař
grifart-enum
Commits
16fc102f
Commit
16fc102f
authored
Jan 10, 2019
by
Jan Kuchař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strictness: enum checks if all values called parent constructor
parent
71079e17
Pipeline
#14408
failed with stages
in 36 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
0 deletions
+51
-0
phpstan.neon
phpstan.neon
+9
-0
src/Internal/Meta.php
src/Internal/Meta.php
+7
-0
tests/Regression/forgotten-constructor-call.phpt
tests/Regression/forgotten-constructor-call.phpt
+35
-0
No files found.
phpstan.neon
View file @
16fc102f
...
...
@@ -2,3 +2,12 @@ includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/grifart/phpstan-oneline/config.neon
parameters:
ignoreErrors:
# for phpstan 0.11
# -
# message: '#Strict comparison using === between int\\|string and null will always evaluate to false#'
# path: src/Internal/Meta.php
- '#Strict comparison using === between int\\|string and null will always evaluate to false#'
\ No newline at end of file
src/Internal/Meta.php
View file @
16fc102f
...
...
@@ -51,6 +51,13 @@ final class Meta
foreach
(
$values
as
$value
)
{
$scalar
=
$value
->
toScalar
();
if
(
$scalar
===
NULL
)
{
throw
new
UsageException
(
"Parent constructor has not been called while constructing one of
{
$this
->
getClass
()
}
enum values."
);
}
if
(
isset
(
$scalarToValues
[
$scalar
]))
{
throw
new
UsageException
(
'You have provided duplicated scalar values.'
);
}
...
...
tests/Regression/forgotten-constructor-call.phpt
0 → 100644
View file @
16fc102f
<?php
declare
(
strict_types
=
1
);
use
Grifart\Enum\UsageException
;
use
Tester\Assert
;
require
__DIR__
.
'/../bootstrap.php'
;
/**
* @method static ForgottenConstructorCall VALUE1()
*/
abstract
class
ForgottenConstructorCall
extends
\
Grifart\Enum\Enum
{
private
const
VALUE1
=
1
;
protected
static
function
provideInstances
():
array
{
return
[
new
class
extends
ForgottenConstructorCall
{
/** @noinspection PhpMissingParentConstructorInspection */
protected
function
__construct
()
{
// no parent call
}
},
];
}
}
Assert
::
exception
(
function
()
{
ForgottenConstructorCall
::
VALUE1
();
},
UsageException
::
class
,
'Parent constructor has not been called while constructing one of ForgottenConstructorCall enum values.'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment