TrialTask::unsetTrialEndsAtAction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 3
nop 0
dl 0
loc 15
ccs 0
cts 12
cp 0
crap 12
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
namespace Canvas\Cli\Tasks;
4
5
use Phalcon\Cli\Task as PhTask;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cli\Task was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Canvas\Models\Subscription;
7
use Carbon\Carbon;
0 ignored issues
show
Bug introduced by
The type Carbon\Carbon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use \Datetime;
9
10
class TrialTask extends PhTask
11
{
12
    /**
13
     * Unset subscription trial_ends_at if trial has ended.
14
     * @return void
15
     */
16
    public function unsetTrialEndsAtAction(): void
17
    {
18
        $subscriptions = Subscription::find([
19
            'conditions' => 'is_deleted = 0 and is_active = 1'
20
        ]);
21
22
        foreach ($subscriptions as $subscription) {
23
            $trialEnds = new Datetime($subscription->trial_ends_at);
24
            $trialEnds->setTime(0, 0);
25
            $formattedTrialEnds = $trialEnds->format('Y-m-d');
26
27
            if ($formattedTrialEnds == Carbon::today()->toDateString()) {
28
                $subscription->trial_ends_at = null;
29
                $subscription->updateOrFail();
30
                echo("Company: {$subscription->id} trial has ended, so its trial_ends_at is NULL \n");
31
            }
32
        }
33
    }
34
}
35