WorkflowActionInstance::fieldLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
/**
3
 * A workflow action attached to a {@link WorkflowInstance} that has been run,
4
 * and is either currently running, or has finished.
5
 *
6
 * Each step of the workflow has one of these created for it - it refers back
7
 * to the original action definition, but is unique for each step of the
8
 * workflow to ensure re-entrant behaviour.
9
 *
10
 * @license BSD License (http://silverstripe.org/bsd-license/)
11
 * @package advancedworkflow
12
 */
13
class WorkflowActionInstance extends DataObject {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
15
	private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
		'Comment'  => 'Text',
17
		'Finished' => 'Boolean'
18
	);
19
20
	private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
		'Workflow'   => 'WorkflowInstance',
22
		'BaseAction' => 'WorkflowAction',
23
		'Member'     => 'Member'
24
	);
25
26
	private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
		'BaseAction.Title',
28
		'Comment',
29
		'Created',
30
		'Member.Name',
31
	);
32
33
	public function fieldLabels($includerelations = true) {
34
		$labels = parent::fieldLabels($includerelations);
35
		$labels['BaseAction.Title'] = _t('WorkflowActionInstance.Title', 'Title');
36
		$labels['Comment'] = _t('WorkflowAction.CommentLabel', 'Comment');
37
		$labels['Member.Name'] = _t('WorkflowAction.Author', 'Author');
38
		$labels['Finished'] = _t('WorkflowAction.FinishedLabel', 'Finished');
39
		$labels['BaseAction.Title'] = _t('WorkflowAction.TITLE', 'Title');
40
41
		return $labels;
42
	}
43
44
	/**
45
	 * Gets fields for when this is part of an active workflow
46
	 */
47
	public function updateWorkflowFields($fields) {
48
		if ($this->BaseAction()->AllowCommenting) {
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
			$fields->push(new TextareaField('Comment', _t('WorkflowAction.COMMENT', 'Comment')));
50
		}
51
	}
52
53
	public function updateFrontendWorkflowFields($fields){
54
		if ($this->BaseAction()->AllowCommenting) {
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
55
			$fields->push(new TextareaField('WorkflowActionInstanceComment', _t('WorkflowAction.FRONTENDCOMMENT', 'Comment')));
56
		}
57
58
		$ba = $this->BaseAction();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59
		$fields = $ba->updateFrontendWorkflowFields($fields, $this->Workflow());
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
Unused Code introduced by
$fields 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...
60
	}
61
62
	/**
63
	 * Gets Front-End DataObject
64
	 *
65
	 * Use the DataObject as defined in the WorkflowAction, otherwise fall back to the
66
	 * context object.
67
	 *
68
	 * Useful for situations where front end workflow deals with multiple data objects
69
	 *
70
	 * @return DataObject
71
	 */
72
	public function getFrontEndDataObject() {
73
		$obj = null;
0 ignored issues
show
Unused Code introduced by
$obj 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...
74
		$ba = $this->BaseAction();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
75
76
		if ($ba->hasMethod('getFrontEndDataObject')) {
77
			$obj = $ba->getFrontEndDataObject();
78
		} else {
79
			$obj = $this->Workflow()->getTarget();
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
80
		}
81
82
		return $obj;
83
	}
84
85
	public function updateFrontEndWorkflowActions($actions) {
86
		$ba = $this->BaseAction();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
87
88
		if ($ba->hasMethod('updateFrontEndWorkflowActions')) {
89
			$ba->updateFrontEndWorkflowActions($actions);
90
		}
91
	}
92
93
	public function getRequiredFields() {
94
		$validator = null;
95
		$ba = $this->BaseAction();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
96
97
		if ($ba->hasMethod('getRequiredFields')) {
98
			$validator = $ba->getRequiredFields();
99
		}
100
101
		return $validator;
102
	}
103
104
	public function setFrontendFormRequirements() {
105
		$ba = $this->BaseAction();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
106
107
		if ($ba->hasMethod('setFrontendFormRequirements')) {
108
			$ba->setFrontendFormRequirements();
109
		}
110
	}
111
112
	public function doFrontEndAction(array $data, Form $form, SS_HTTPRequest $request) {
113
		//Save Front End Workflow notes, then hand over to Workflow Action
114
		if (isset($data["WorkflowActionInstanceComment"])) {
115
			$this->Comment = $data["WorkflowActionInstanceComment"];
0 ignored issues
show
Documentation introduced by
The property Comment does not exist on object<WorkflowActionInstance>. 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...
116
			$this->write();
117
		}
118
119
		$ba = $this->BaseAction();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
120
		if ($ba->hasMethod('doFrontEndAction')) {
121
			$ba->doFrontEndAction($data, $form, $request);
122
		}
123
	}
124
125
126
	/**
127
	 * Gets the title of this active action instance
128
	 *
129
	 * @return string
130
	 */
131
	public function getTitle() {
132
		return $this->BaseAction()->Title;
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
133
	}
134
135
	/**
136
	 * Returns all the valid transitions that lead out from this action.
137
	 *
138
	 * This is called if this action has finished, and the workflow engine wants
139
	 * to run the next action.
140
	 *
141
	 * If this action returns only one valid transition it will be immediately
142
	 * followed; otherwise the user will decide which transition to follow.
143
	 *
144
	 * @return ArrayList
145
	 */
146
	public function getValidTransitions() {
147
		$available = $this->BaseAction()->Transitions();
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
148
		$valid     = new ArrayList();
149
150
		// iterate through the transitions and see if they're valid for the current state of the item being
151
		// workflowed
152
		if($available) foreach($available as $transition) {
153
			if($transition->isValid($this->Workflow())) $valid->push($transition);
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
154
		}
155
156
		return $valid;
157
	}
158
159
	/**
160
	 * Called when this instance is started within the workflow
161
	 */
162
	public function actionStart(WorkflowTransition $transition) {
163
		$this->extend('onActionStart', $transition);
164
	}
165
166
	/**
167
	 * Called when this action has been completed within the workflow
168
	 */
169
	public function actionComplete(WorkflowTransition $transition) {
170
		$this->MemberID = Member::currentUserID();
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<WorkflowActionInstance>. 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
		$this->write();
172
		$this->extend('onActionComplete', $transition);
173
	}
174
175
176
	/**
177
	 * Can documents in the current workflow state be edited?
178
	 *
179
	 * @param  DataObject $target
180
	 * @return bool
181
	 */
182
	public function canEditTarget(DataObject $target) {
183
		$absolute = $this->BaseAction()->canEditTarget($target);
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
184
		if (!is_null($absolute)) {
185
			return $absolute;
186
		}
187
		switch ($this->BaseAction()->AllowEditing) {
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
188
			case 'By Assignees':
189
				return $this->Workflow()->canEdit();
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
190
			case 'No':
191
				return false;
192
			case 'Content Settings':
193
			default:
194
				return null;
195
		}
196
	}
197
198
	/**
199
	 * Does this action restrict viewing of the document?
200
	 *
201
	 * @param  DataObject $target
202
	 * @return bool
203
	 */
204
	public function canViewTarget(DataObject $target) {
205
		return $this->BaseAction()->canViewTarget($target);
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
206
	}
207
208
	/**
209
	 * Does this action restrict the publishing of a document?
210
	 *
211
	 * @param  DataObject $target
212
	 * @return bool
213
	 */
214
	public function canPublishTarget(DataObject $target) {
215
		$absolute = $this->BaseAction()->canPublishTarget($target);
0 ignored issues
show
Documentation Bug introduced by
The method BaseAction does not exist on object<WorkflowActionInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
216
		if (!is_null($absolute)) {
217
			return $absolute;
218
		}
219
		return false;
220
	}
221
222
	public function canView($member = null) {
223
		return $this->Workflow()->canView($member);
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
224
	}
225
226
	public function canEdit($member = null) {
227
		return $this->Workflow()->canEdit($member);
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
228
	}
229
230
	public function canDelete($member = null) {
231
		return $this->Workflow()->canDelete($member);
0 ignored issues
show
Bug introduced by
The method Workflow() does not exist on WorkflowActionInstance. Did you maybe mean updateWorkflowFields()?

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...
232
	}
233
}