WorkflowPublishTargetJob   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 4
A __construct() 0 7 3
A getTitle() 0 11 1
1
<?php
2
/**
3
 * A queued job that publishes a target after a delay.
4
 *
5
 * @package advancedworkflow
6
 */
7
class WorkflowPublishTargetJob extends AbstractQueuedJob {
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...
8
9
	public function __construct($obj = null, $type = null) {
10
		if ($obj) {
11
			$this->setObject($obj);
12
			$this->publishType = $type ? strtolower($type) : 'publish';
13
			$this->totalSteps = 1;
14
		}
15
	}
16
17
	public function getTitle() {
18
		return _t(
19
			'AdvancedWorkflowPublishJob.SCHEDULEJOBTITLE',
20
			"Scheduled {type} of {object}",
21
			"",
22
			array(
0 ignored issues
show
Documentation introduced by
array('type' => $this->p...is->getObject()->Title) is of type array<string,?,{"type":"?","object":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
				'type' => $this->publishType,
24
				'object' => $this->getObject()->Title
25
			)
26
		);
27
	}
28
29
	public function process() {
30
		if ($target = $this->getObject()) {
31
			if ($this->publishType == 'publish') {
32
				$target->setIsPublishJobRunning(true);
33
				$target->PublishOnDate = '';
34
				$target->writeWithoutVersion();
35
				$target->doPublish();
36
			} else if ($this->publishType == 'unpublish') {
37
				$target->setIsPublishJobRunning(true);
38
				$target->UnPublishOnDate = '';
39
				$target->writeWithoutVersion();
40
				$target->doUnpublish();
41
			}
42
		}
43
		$this->currentStep = 1;
44
		$this->isComplete = true;
45
	}
46
47
}