PyRowMan /
pheanstalk
| 1 | <?php |
||||
| 2 | |||||
| 3 | |||||
| 4 | namespace Pheanstalk\Structure; |
||||
| 5 | |||||
| 6 | use Doctrine\Common\Collections\ArrayCollection; |
||||
| 7 | |||||
| 8 | class Job |
||||
| 9 | { |
||||
| 10 | /** @var ArrayCollection[Task] */ |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 11 | private $tasks; |
||||
| 12 | |||||
| 13 | /** |
||||
| 14 | * Job constructor. |
||||
| 15 | * |
||||
| 16 | * @param ArrayCollection[Task] $tasks |
||||
|
0 ignored issues
–
show
|
|||||
| 17 | */ |
||||
| 18 | 16 | public function __construct(ArrayCollection $tasks) |
|||
| 19 | { |
||||
| 20 | 16 | $this->setTasks($tasks); |
|||
| 21 | } |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * @return ArrayCollection |
||||
| 25 | */ |
||||
| 26 | 9 | public function getTasks(): ArrayCollection |
|||
| 27 | { |
||||
| 28 | 9 | return $this->tasks; |
|||
| 29 | } |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * @param ArrayCollection $tasks |
||||
| 33 | * |
||||
| 34 | * @return Job |
||||
| 35 | */ |
||||
| 36 | 16 | public function setTasks(ArrayCollection $tasks): Job |
|||
| 37 | { |
||||
| 38 | $this->tasks = $tasks->filter(function (Task $task) { |
||||
|
0 ignored issues
–
show
The parameter
$task is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 39 | 16 | return true; |
|||
| 40 | 16 | }); |
|||
| 41 | 16 | return $this; |
|||
| 42 | } |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * @param Task $task |
||||
| 46 | * |
||||
| 47 | * @return Job |
||||
| 48 | */ |
||||
| 49 | 1 | public function addTask(Task $task): Job |
|||
| 50 | { |
||||
| 51 | 1 | $this->tasks[] = $task; |
|||
| 52 | 1 | return $this; |
|||
| 53 | } |
||||
| 54 | |||||
| 55 | /** |
||||
| 56 | * @param Task $task |
||||
| 57 | * |
||||
| 58 | * @return Job |
||||
| 59 | */ |
||||
| 60 | 1 | public function removeTask(Task $task): Job |
|||
| 61 | { |
||||
| 62 | 1 | $this->tasks->removeElement($task); |
|||
| 63 | 1 | return $this; |
|||
| 64 | } |
||||
| 65 | |||||
| 66 | /** |
||||
| 67 | * @return \DOMDocument |
||||
| 68 | * @throws \ReflectionException |
||||
| 69 | */ |
||||
| 70 | 8 | public function getXml() |
|||
| 71 | { |
||||
| 72 | 8 | $dom = new \DOMDocument("1.0", "utf-8"); |
|||
| 73 | 8 | $root = $dom->createElement("job"); |
|||
| 74 | 8 | $tasks = $dom->createElement("tasks"); |
|||
| 75 | /** @var Task $task */ |
||||
| 76 | 8 | foreach ($this->getTasks() as $task) { |
|||
| 77 | 8 | $taskItem = $dom->createElement("task"); |
|||
|
0 ignored issues
–
show
|
|||||
| 78 | 8 | $taskNode = $task->getXml()->getElementsByTagName('task')->item(0); |
|||
| 79 | 8 | $tasks->appendChild($dom->importNode($taskNode, true)); |
|||
| 80 | } |
||||
| 81 | 8 | $root->appendChild($tasks); |
|||
| 82 | 8 | $dom->appendChild($root); |
|||
| 83 | 8 | return $dom; |
|||
| 84 | } |
||||
| 85 | } |
||||
| 86 |