Completed
Push — master ( f4119b...0cd623 )
by Mahmoud
04:33
created

UpdateTimeTrackerToCloseTask::run()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 3
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace App\Containers\Tracker\Tasks;
4
5
use App\Containers\Tracker\Data\Repositories\TimeTrackerRepository;
6
use App\Containers\Tracker\Models\TimeTracker;
7
use App\Containers\User\Tasks\FindUserByVisitorIdTask;
8
use App\Port\Action\Abstracts\Action;
9
use Carbon\Carbon;
10
11
/**
12
 * Class UpdateTimeTrackerToCloseTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class UpdateTimeTrackerToCloseTask extends Action
17
{
18
19
    /**
20
     * @var  \App\Containers\User\Tasks\FindUserByVisitorIdTask
21
     */
22
    private $findUserByVisitorIdTask;
23
24
    /**
25
     * @var  \App\Containers\Tracker\Data\Repositories\TimeTrackerRepository
26
     */
27
    private $timeTrackerRepository;
28
29
    /**
30
     * @var  \App\Containers\Tracker\Tasks\FindTimeTrackerTask
31
     */
32
    private $findTimeTrackerTask;
33
34
    /**
35
     * TrackOpenAction constructor.
36
     *
37
     * @param \App\Containers\User\Tasks\FindUserByVisitorIdTask              $findUserByVisitorIdTask
38
     * @param \App\Containers\Tracker\Data\Repositories\TimeTrackerRepository $timeTrackerRepository
39
     */
40
    public function __construct(
41
        FindUserByVisitorIdTask $findUserByVisitorIdTask,
42
        TimeTrackerRepository $timeTrackerRepository,
43
        FindTimeTrackerTask $findTimeTrackerTask
44
    ) {
45
        $this->findUserByVisitorIdTask = $findUserByVisitorIdTask;
46
        $this->timeTrackerRepository = $timeTrackerRepository;
47
        $this->findTimeTrackerTask = $findTimeTrackerTask;
48
    }
49
50
    /**
51
     * @param \App\Containers\Tracker\Models\TimeTracker $timeTracker
52
     *
53
     * @return  \App\Containers\Tracker\Models\TimeTracker|mixed
54
     */
55
    public function run(TimeTracker $timeTracker)
56
    {
57
        if ($timeTracker && $timeTracker->status == TimeTracker::PENDING) {
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<App\Containers\Tracker\Models\TimeTracker>. 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...
58
59
            $now = Carbon::now();
60
61
            // get the time between now and when it was opened
62
            $durationsSeconds = $now->diffInSeconds($timeTracker->open_at);
0 ignored issues
show
Documentation introduced by
The property open_at does not exist on object<App\Containers\Tracker\Models\TimeTracker>. 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...
63
64
            $data = [
65
                'status'   => TimeTracker::SUCCEEDED,
66
                'close_at' => $now,
67
                'duration' => $durationsSeconds,
68
            ];
69
            $this->timeTrackerRepository->update($data, $timeTracker->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Containers\Tracker\Models\TimeTracker>. 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...
70
71
            return true;
72
        }
73
74
        return false;
75
    }
76
}
77