Completed
Push — master ( 0cd623...76b2d2 )
by Mahmoud
05:30
created

CreateOpenTimeTrackTask::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
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\Models\User;
8
use App\Containers\User\Tasks\FindUserByVisitorIdTask;
9
use App\Port\Task\Abstracts\Task;
10
use Carbon\Carbon;
11
12
/**
13
 * Class CreateOpenTimeTrackTask.
14
 *
15
 * @author Mahmoud Zalt <[email protected]>
16
 */
17
class CreateOpenTimeTrackTask extends Task
18
{
19
20
    /**
21
     * @var  \App\Containers\Tracker\Data\Repositories\TimeTrackerRepository
22
     */
23
    private $timeTrackerRepository;
24
25
    /**
26
     * CloseNonClosedTimeTrackerTasks constructor.
27
     *
28
     * @param \App\Containers\Tracker\Data\Repositories\TimeTrackerRepository $timeTrackerRepository
29
     */
30
    public function __construct(TimeTrackerRepository $timeTrackerRepository)
31
    {
32
        $this->timeTrackerRepository = $timeTrackerRepository;
33
    }
34
35
    /**
36
     * @param \App\Containers\User\Models\User $user
37
     *
38
     * @return  \App\Containers\Tracker\Models\TimeTracker|mixed
39
     */
40
    public function run(User $user)
41
    {
42
43
        // create the new record with pending status
44
        $timeTracker = new TimeTracker();
45
        $timeTracker->open_at = Carbon::now();
0 ignored issues
show
Documentation introduced by
The property open_at does not exist on object<App\Containers\Tracker\Models\TimeTracker>. 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...
46
        $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 __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...
47
        $timeTracker->user()->associate($user);
48
        $timeTracker = $this->timeTrackerRepository->create($timeTracker->toArray());
49
50
        return $timeTracker;
51
    }
52
}
53