Completed
Push — master ( 7a08de...9ce2ea )
by Daniel
04:39
created

Task::getEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Commander;
9
10
use Doctrine\ORM\EntityManagerInterface;
11
use GravityMedia\Commander\ORM\TaskEntity;
12
13
/**
14
 * Task class.
15
 *
16
 * @package GravityMedia\Commander\Commander
17
 */
18
class Task
19
{
20
    /**
21
     * The entity manager.
22
     *
23
     * @var EntityManagerInterface
24
     */
25
    protected $entityManager;
26
27
    /**
28
     * The entity.
29
     *
30
     * @var TaskEntity
31
     */
32
    protected $entity;
33
34
    /**
35
     * Create task object.
36
     *
37
     * @param EntityManagerInterface $entityManager
38
     * @param TaskEntity             $entity
39
     */
40 10
    public function __construct(EntityManagerInterface $entityManager, TaskEntity $entity)
41
    {
42 10
        $this->entityManager = $entityManager;
43 10
        $this->entity = $entity;
44 10
    }
45
46
    /**
47
     * Get entity
48
     *
49
     * @return TaskEntity
50
     */
51 2
    public function getEntity()
52
    {
53 2
        return $this->entity;
54
    }
55
56
    /**
57
     * Prioritize task.
58
     *
59
     * @param int $priority
60
     *
61
     * @return $this
62
     */
63 2
    public function prioritize($priority)
64
    {
65 2
        $this->entity->setPriority($priority);
66 2
        $this->entityManager->flush();
67
68 2
        return $this;
69
    }
70
71
    /**
72
     * Begin task.
73
     *
74
     * @param int $pid
75
     *
76
     * @return $this
77
     */
78 2
    public function begin($pid)
79
    {
80 2
        $this->entity->setPid($pid);
81 2
        $this->entityManager->flush();
82
83 2
        return $this;
84
    }
85
86
    /**
87
     * Finish task.
88
     *
89
     * @param int $exitCode
90
     *
91
     * @return $this
92
     */
93 2
    public function finish($exitCode)
94
    {
95 2
        $this->entity->setExitCode($exitCode);
96 2
        $this->entityManager->flush();
97
98 2
        return $this;
99
    }
100
101
    /**
102
     * Remove task.
103
     *
104
     * @return $this
105
     */
106 2
    public function remove()
107
    {
108 2
        $this->entityManager->remove($this->entity);
109 2
        $this->entityManager->flush();
110
111 2
        return $this;
112
    }
113
}
114