Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workflow] Clarify validator API + fixed unknown "scalar" marking store #20492

Closed
wants to merge 6 commits into from
Closed

[Workflow] Clarify validator API + fixed unknown "scalar" marking store #20492

wants to merge 6 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Nov 11, 2016

Q A
Branch? "master"
Bug fix? yes
New feature? no
BC breaks? no, if merged in 3.2
Deprecations? no
Tests pass? yes
Fixed tickets comma-separated list of tickets fixed by the PR, if any
License MIT
Doc PR reference to the documentation PR, if any

See also https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php#L48

@ro0NL
Copy link
Contributor Author

ro0NL commented Nov 11, 2016

@HeahDude sorry missed your changes in #20490, to me this makes more sense, rather then combining true and throw.

@xabbuh
Copy link
Member

xabbuh commented Nov 12, 2016

I agree that it is not really intuitive to throw an exception in case of an invalid definition, but return true otherwise.

@@ -23,7 +23,7 @@
* @param Definition $definition
* @param string $name
*
* @return bool
* @return void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed entirely

@ro0NL
Copy link
Contributor Author

ro0NL commented Nov 13, 2016

So.. what about removing the WorkflowValidator - #20490 (comment)?

Looks like a premature optimization to me.. and im not even sure validators should resemble a semi same inheritance tree.

edit: affects https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php#L68

@ro0NL
Copy link
Contributor Author

ro0NL commented Nov 13, 2016

Back to 1 workflow validator and 1 state machine validator seems most intuitive to me =/

@HeahDude
Copy link
Contributor

You should not validate every workflows as a single place workflow, this feels wrong to me.

@ro0NL
Copy link
Contributor Author

ro0NL commented Nov 13, 2016

Not sure i understand.. right now it's optin.

@HeahDude
Copy link
Contributor

Ok haven't look at the code yet :p

@@ -59,19 +58,24 @@ private function getValidator($tag)
{
if ($tag['type'] === 'state_machine') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use yoda condition

@@ -59,19 +58,24 @@ private function getValidator($tag)
{
if ($tag['type'] === 'state_machine') {
$name = 'state_machine';
$class = StateMachineValidator::class;
} elseif ($tag['marking_store'] === 'scalar') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single_state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a bug fix right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed since 08464c9

Copy link
Contributor

@HeahDude HeahDude Nov 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you're already at bug fixing :)

} elseif ($tag['marking_store'] === 'scalar') {
$name = 'single_place';
$class = SinglePlaceWorkflowValidator::class;
$name = 'workflow_single_place';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should rename this workflow_single_state for consistency

foreach ($definition->getTransitions() as $transition) {
if (1 < count($transition->getTos())) {
throw new InvalidDefinitionException(
sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be inlined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

public function validate(Definition $definition, $name)
{
if ($this->singlePlace) {
foreach ($definition->getTransitions() as $transition) {
if (1 < count($transition->getTos())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If (count($transition->getTos()) > 1)

Copy link
Contributor Author

@ro0NL ro0NL Nov 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was, as is, accepted before (and is actually yoda style). Not sure we should change it now..

}

return $this->validators[$name];
switch ($name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit cumbersome to have a if / else then the same switch
And IMHO, we could remove the cache layer to make code simpler. it's a premature optimization that does not bring real perf improvement .

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little comment, and after that I'm Ok with this PR.

@lyrixx lyrixx removed the Bug label Nov 14, 2016
@lyrixx
Copy link
Member

lyrixx commented Nov 14, 2016

👍


(I removed the Bug label, since it's not a bug. Could you edit your PR description?)

if ($tag['type'] === 'state_machine') {
$name = 'state_machine';
$class = StateMachineValidator::class;
} elseif ($tag['marking_store'] === 'scalar') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is a kind of bug :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing from 08464c9.

Copy link
Contributor Author

@ro0NL ro0NL Nov 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR description title.

@ro0NL ro0NL changed the title [Workflow] Improved validator PHPdoc clarifying its API [Workflow] Clarify validator API + fixed unknown "scalar" marking store Nov 14, 2016
@lyrixx
Copy link
Member

lyrixx commented Nov 15, 2016

Good catch, thanks @ro0NL.

@lyrixx lyrixx closed this in e4e6380 Nov 15, 2016
@ro0NL ro0NL deleted the workflow/validator-api branch November 15, 2016 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants