GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (446)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/WorkflowEngineTest.php (33 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Tests;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Versioned\Versioned;
9
use Symbiote\AdvancedWorkflow\Actions\AssignUsersToWorkflowAction;
10
use Symbiote\AdvancedWorkflow\Actions\NotifyUsersWorkflowAction;
11
use Symbiote\AdvancedWorkflow\Actions\PublishItemWorkflowAction;
12
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
13
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowDefinition;
14
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
15
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowTransition;
16
use Symbiote\AdvancedWorkflow\Templates\WorkflowTemplate;
17
18
/**
19
 * Tests for the workflow engine.
20
 *
21
 * @author     [email protected]
22
 * @license    BSD License (http://silverstripe.org/bsd-license/)
23
 * @package    advancedworkflow
24
 * @subpackage tests
25
 */
26
class WorkflowEngineTest extends SapphireTest
27
{
28
    protected static $fixture_file = 'workflowinstancetargets.yml';
29
30
    public function testCreateWorkflowInstance()
31
    {
32
        $definition = new WorkflowDefinition();
33
        $definition->Title = "Create Workflow Instance";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...cts\WorkflowDefinition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
34
        $definition->write();
35
36
        $stepOne = new WorkflowAction();
37
        $stepOne->Title = "Step One";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
        $stepOne->WorkflowDefID = $definition->ID;
0 ignored issues
show
The property WorkflowDefID does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
39
        $stepOne->write();
40
41
        $stepTwo = new WorkflowAction();
42
        $stepTwo->Title = "Step Two";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
43
        $stepTwo->WorkflowDefID = $definition->ID;
0 ignored issues
show
The property WorkflowDefID does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
44
        $stepTwo->write();
45
46
        $transitionOne = new WorkflowTransition();
47
        $transitionOne->Title = 'Step One T1';
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
        $transitionOne->ActionID = $stepOne->ID;
0 ignored issues
show
The property ActionID does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
49
        $transitionOne->NextActionID = $stepTwo->ID;
0 ignored issues
show
The property NextActionID does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
        $transitionOne->write();
51
52
        $instance = new WorkflowInstance();
53
        $instance->write();
54
55
        $instance->beginWorkflow($definition);
56
57
        $actions = $definition->Actions();
0 ignored issues
show
The method Actions() does not exist on Symbiote\AdvancedWorkflo...ects\WorkflowDefinition. Did you maybe mean updateAdminActions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
58
        $this->assertEquals(2, $actions->Count());
59
60
        $transitions = $actions->find('Title', 'Step One')->Transitions();
61
        $this->assertEquals(1, $transitions->Count());
62
    }
63
64
    public function testExecuteImmediateWorkflow()
65
    {
66
        $def = $this->createDefinition();
67
68
        $actions = $def->Actions();
0 ignored issues
show
The method Actions() does not exist on Symbiote\AdvancedWorkflo...ects\WorkflowDefinition. Did you maybe mean updateAdminActions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
$actions is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
69
        $firstAction = $def->getInitialAction();
70
        $this->assertEquals('Step One', $firstAction->Title);
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
71
72
        $instance = new WorkflowInstance();
73
        $instance->beginWorkflow($def);
74
        $this->assertTrue($instance->CurrentActionID > 0);
0 ignored issues
show
The property CurrentActionID does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
75
76
        $instance->execute();
77
78
        // the instance should be complete, and have two finished workflow action
79
        // instances.
80
        $actions = $instance->Actions();
0 ignored issues
show
The method Actions() does not exist on Symbiote\AdvancedWorkflo...bjects\WorkflowInstance. Did you maybe mean getFrontEndWorkflowActions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
81
        $this->assertEquals(2, $actions->Count());
82
83
        foreach ($actions as $action) {
84
            $this->assertTrue((bool) $action->Finished);
85
        }
86
    }
87
88
    /**
89
     * Ensure WorkflowInstance returns expected values for a Published target object.
90
     */
91 View Code Duplication
    public function testInstanceGetTargetPublished()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        $def = $this->createDefinition();
94
        $target = $this->objFromFixture(SiteTree::class, 'published-object');
95
        $target->publishRecursive();
96
97
        $instance = $this->objFromFixture(WorkflowInstance::class, 'target-is-published');
98
        $instance->beginWorkflow($def);
99
        $instance->execute();
100
101
        $this->assertTrue($target->isPublished());
102
        $this->assertEquals($target->ID, $instance->getTarget()->ID);
103
        $this->assertEquals($target->Title, $instance->getTarget()->Title);
104
    }
105
106
    /**
107
     * Ensure WorkflowInstance returns expected values for a Draft target object.
108
     */
109 View Code Duplication
    public function testInstanceGetTargetDraft()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $def = $this->createDefinition();
112
        $target = $this->objFromFixture(SiteTree::class, 'draft-object');
113
114
        $instance = $this->objFromFixture(WorkflowInstance::class, 'target-is-draft');
115
        $instance->beginWorkflow($def);
116
        $instance->execute();
117
118
        $this->assertFalse($target->isPublished());
119
        $this->assertEquals($target->ID, $instance->getTarget()->ID);
120
        $this->assertEquals($target->Title, $instance->getTarget()->Title);
121
    }
122
123
    public function testPublishAction()
124
    {
125
        $this->logInWithPermission();
126
127
        $action = new PublishItemWorkflowAction;
128
        $instance = new WorkflowInstance();
129
130
        $page = new SiteTree();
131
        $page->Title = 'stuff';
132
        $page->write();
133
134
        $instance->TargetClass = SiteTree::class;
0 ignored issues
show
The property TargetClass does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
135
        $instance->TargetID = $page->ID;
0 ignored issues
show
The property TargetID does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
136
137
        $this->assertFalse($page->isPublished());
138
139
        $action->execute($instance);
140
141
        $page = DataObject::get_by_id(SiteTree::class, $page->ID);
142
        $this->assertTrue($page->isPublished());
143
    }
144
145
    public function testCreateDefinitionWithEmptyTitle()
146
    {
147
        $definition = new WorkflowDefinition();
148
        $definition->Title = "";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...cts\WorkflowDefinition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
149
        $definition->write();
150
        $this->assertContains(
151
            'My Workflow',
152
            $definition->Title,
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...cts\WorkflowDefinition>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
153
            'Workflow created without title is assigned a default title.'
154
        );
155
    }
156
157 View Code Duplication
    protected function createDefinition()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $definition = new WorkflowDefinition();
160
        $definition->Title = "Dummy Workflow Definition";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...cts\WorkflowDefinition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
161
        $definition->write();
162
163
        $stepOne = new WorkflowAction();
164
        $stepOne->Title = "Step One";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
165
        $stepOne->WorkflowDefID = $definition->ID;
0 ignored issues
show
The property WorkflowDefID does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
166
        $stepOne->write();
167
168
        $stepTwo = new WorkflowAction();
169
        $stepTwo->Title = "Step Two";
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
170
        $stepTwo->WorkflowDefID = $definition->ID;
0 ignored issues
show
The property WorkflowDefID does not exist on object<Symbiote\Advanced...Objects\WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
171
        $stepTwo->write();
172
173
        $transitionOne = new WorkflowTransition();
174
        $transitionOne->Title = 'Step One T1';
0 ignored issues
show
The property Title does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
175
        $transitionOne->ActionID = $stepOne->ID;
0 ignored issues
show
The property ActionID does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
176
        $transitionOne->NextActionID = $stepTwo->ID;
0 ignored issues
show
The property NextActionID does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
177
        $transitionOne->write();
178
179
        return $definition;
180
    }
181
182
    public function testCreateFromTemplate()
183
    {
184
        $structure = array(
185
            'First step'    => array(
186
                'type'      => AssignUsersToWorkflowAction::class,
187
                'transitions'   => array(
188
                    'second'    => 'Second step'
189
                )
190
            ),
191
            'Second step'   => array(
192
                'type'      => NotifyUsersWorkflowAction::class,
193
                'transitions'   => array(
194
                    'Approve'   => 'Third step'
195
                )
196
            ),
197
        );
198
199
        $template = new WorkflowTemplate('Test');
200
201
        $template->setStructure($structure);
202
203
        $actions = $template->createRelations();
204
205
        $this->assertEquals(2, count($actions));
206
        $this->assertTrue(isset($actions['First step']));
207
        $this->assertTrue(isset($actions['Second step']));
208
209
        $this->assertTrue($actions['First step']->exists());
210
211
        $transitions = $actions['First step']->Transitions();
212
213
        $this->assertTrue($transitions->count() == 1);
214
    }
215
216
    /**
217
     * Tests whether if user(s) are able to delete a workflow, dependent on permissions.
218
     */
219
    public function testCanDeleteWorkflow()
220
    {
221
        // Create a definition
222
        $def = $this->createDefinition();
223
224
        // Test a user with lame permissions
225
        $memberID = $this->logInWithPermission('SITETREE_VIEW_ALL');
226
        $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $memberID);
227
        $this->assertFalse($def->canCreate($member));
0 ignored issues
show
It seems like $member defined by \SilverStripe\ORM\DataOb...ty\\Member', $memberID) on line 226 can also be of type object<SilverStripe\ORM\DataObject>; however, Symbiote\AdvancedWorkflo...Definition::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
228
229
        // Test a user with good permissions
230
        $memberID = $this->logInWithPermission('CREATE_WORKFLOW');
231
        $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $memberID);
232
        $this->assertTrue($def->canCreate($member));
0 ignored issues
show
It seems like $member defined by \SilverStripe\ORM\DataOb...ty\\Member', $memberID) on line 231 can also be of type object<SilverStripe\ORM\DataObject>; however, Symbiote\AdvancedWorkflo...Definition::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
233
    }
234
235
    /**
236
     * For a context around this test, see: https://github.com/symbiote/advancedworkflow/issues/141
237
     *
238
     *  1). Create a workflow definition
239
     *  2). Step the content into that workflow
240
     *  3). Delete the workflow
241
     *  4). Check that the content:
242
     *      i). Has no remaining related actions
243
     *      ii). Can be re-assigned a new Workflow
244
     *  5). Check that the object under workflow, maintains its status (Draft, Published etc)
245
     */
246
    public function testDeleteWorkflowTargetStillWorks()
247
    {
248
        // 1). Create a workflow definition
249
        $def = $this->createDefinition();
250
        $page = SiteTree::create();
251
        $page->Title = 'dummy test';
252
        $page->WorkflowDefinitionID = $def->ID;     // Normally done via CMS
253
        Versioned::set_stage(Versioned::DRAFT);
254
        $page->write();
255
256
        // Check $page is in draft, pre-deletion
257
        $status = ($page->isOnDraftOnly() && !$page->isPublished());
258
        $this->assertTrue($status);
259
260
        // 2). Step the content into that workflow
261
        $instance = new WorkflowInstance();
262
        $instance->beginWorkflow($def, $page);
263
        $instance->execute();
264
265
        // Check the content is assigned
266
        $testPage = DataObject::get_by_id(SiteTree::class, $page->ID);
267
        $this->assertEquals($instance->TargetID, $testPage->ID);
0 ignored issues
show
The property TargetID does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
268
269
        // 3). Delete the workflow
270
        $def->delete();
271
272
        // Check $testPage is _still_ in draft, post-deletion
273
        $status = ($testPage->isOnDraftOnly() && !$testPage->isPublished());
274
        $this->assertTrue($status);
275
276
        /*
277
         * 4). i). Check that the content: Has no remaining related actions
278
         * Note: WorkflowApplicable::WorkflowDefinitionID does _not_ get updated until assigned a new workflow
279
         * so we can use it to check that all related actions are gone
280
         */
281
        $defID = $testPage->WorkflowDefinitionID;
282
        $this->assertEquals(0, DataObject::get(WorkflowAction::class)->filter('WorkflowDefID', $defID)->count());
283
284
        /*
285
         * 4). ii). Check that the content: Can be re-assigned a new Workflow Definition
286
         */
287
        $newDef = $this->createDefinition();
288
        $testPage->WorkflowDefinitionID = $newDef->ID;  // Normally done via CMS
289
        $instance = new WorkflowInstance();
290
        $instance->beginWorkflow($newDef, $testPage);
291
        $instance->execute();
292
293
        // Check the content is assigned to the new Workflow Definition correctly
294
        $this->assertEquals($newDef->ID, $testPage->WorkflowDefinitionID);
295
        $this->assertEquals(
296
            $newDef->Actions()->count(),
0 ignored issues
show
The method Actions() does not exist on Symbiote\AdvancedWorkflo...ects\WorkflowDefinition. Did you maybe mean updateAdminActions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
297
            DataObject::get(WorkflowAction::class)->filter('WorkflowDefID', $newDef->ID)->count()
298
        );
299
300
        // 5). Check that the object under workflow, maintains its status
301
        $newDef2 = $this->createDefinition();
302
303
        // Login so SiteTree::canPublish() returns true
304
        $testPage->WorkflowDefinitionID = $newDef2->ID;     // Normally done via CMS
305
        $this->logInWithPermission();
306
        $testPage->publishRecursive();
307
308
        // Check $testPage is published, pre-deletion (getStatusFlags() returns empty array)
309
        $this->assertTrue($testPage->isPublished());
310
311
        $instance = new WorkflowInstance();
312
        $instance->beginWorkflow($newDef2, $testPage);
313
        $instance->execute();
314
315
        // Now delete the related WorkflowDefinition and ensure status is the same
316
        // (i.e. so it's not 'modified' for example)
317
        $newDef2->delete();
318
319
        // Check $testPage is _still_ published, post-deletion (getStatusFlags() returns empty array)
320
        $this->assertTrue($testPage->isPublished());
321
    }
322
323
    /**
324
     * Test the diff showing only fields that have changes made to it in a data object.
325
     */
326
    public function testInstanceDiff()
327
    {
328
        $instance = $this->objFromFixture(WorkflowInstance::class, 'target-is-published');
329
        $target = $instance->getTarget();
330
        $target->publishRecursive();
331
332
        $target->Title = 'New title for target';
333
        $target->write();
334
335
        $diff = $instance->getTargetDiff()->column('Name');
336
        $this->assertContains('Title', $diff);
337
        $this->assertNotContains('Content', $diff);
338
    }
339
}
340