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.

WorkflowReminderTask::run()   B
last analyzed

Complexity

Conditions 8
Paths 3

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 7.8682
c 0
b 0
f 0
cc 8
nc 3
nop 1
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Tasks;
4
5
use SilverStripe\Dev\BuildTask;
6
use SilverStripe\CMS\Model\SiteTree;
7
use SilverStripe\Control\Email\Email;
8
use SilverStripe\ORM\FieldType\DBDatetime;
9
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowDefinition;
10
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
11
12
/**
13
 * A task that sends a reminder email to users assigned to a workflow that has
14
 * not been actioned for n days.
15
 *
16
 * @package advancedworkflow
17
 */
18
class WorkflowReminderTask extends BuildTask
19
{
20
    protected $title       = 'Workflow Reminder Task';
21
    protected $description = 'Sends out workflow reminder emails to stale workflow instances';
22
23
    private static $segment = 'WorkflowReminderTask';
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...
24
25
    public function run($request)
26
    {
27
        $sent = 0;
28
        if (WorkflowInstance::get()->count()) { // Don't attempt the filter if no instances -- prevents a crash
29
            $active = WorkflowInstance::get()
30
                ->innerJoin('WorkflowDefinition', '"DefinitionID" = "WorkflowDefinition"."ID"')
31
                ->filter(array(
32
                    'WorkflowStatus' => array('Active', 'Paused')
33
                ))->where('RemindDays > 0');
34
35
            if ($active->exists()) {
36
                foreach ($active as $instance) {
37
                    $edited = strtotime($instance->LastEdited);
38
                    $days   = $instance->Definition()->RemindDays;
39
40
                    if ($edited + $days * 3600 * 24 > DBDatetime::now()->getTimestamp()) {
41
                        continue;
42
                    }
43
44
                    $email   = new Email();
45
                    $bcc     = '';
0 ignored issues
show
Unused Code introduced by
$bcc 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...
46
                    $members = $instance->getAssignedMembers();
47
                    $target  = $instance->getTarget();
48
49
                    if (!$members || !count($members)) {
50
                        continue;
51
                    }
52
53
                    $email->setSubject("Workflow Reminder: $instance->Title");
54
                    $email->setBCC($members->column('Email'));
55
                    $email->setHTMLTemplate('email\\WorkflowReminderEmail');
56
                    $email->setData(array(
57
                        'Instance' => $instance,
58
                        'Link' => $target instanceof SiteTree ? "admin/show/$target->ID" : '',
59
                        'Diff' => $instance->getTargetDiff()
60
                    ));
61
62
                    $email->send();
63
64
65
                    $sent++;
66
67
                    $instance->LastEdited = DBDatetime::now()->getTimestamp();
68
                    $instance->write();
69
                }
70
            }
71
        }
72
        echo "Sent $sent workflow reminder emails.\n";
73
    }
74
}
75