Completed
Push — master ( 30a2b5...89612e )
by Axel
02:59
created

UserStoryManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Scrumban\Manager;
4
5
use Scrumban\Entity\UserStory;
6
use Scrumban\Entity\Sprint;
7
8
use Doctrine\Common\Persistence\ObjectManager;
9
10
use Scrumban\Event\UserStoryCreationEvent;
11
use Scrumban\Event\UserStoryUpdateEvent;
12
13
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14
15
final class UserStoryManager
16
{
17
    /** @var ObjectManager **/
18
    private $om;
19
    /** @var EventDispatcherInterface **/
20
    private $eventDispatcher;
21
    
22
    public function __construct(ObjectManager $om, EventDispatcherInterface $eventDispatcher)
23
    {
24
        $this->om = $om;
25
        $this->eventDispatcher = $eventDispatcher;
26
    }
27
    
28
    public function createUserStory(string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, Sprint $sprint = null): UserStory
29
    {
30
        $userStory =
31
            (new UserStory())
32
            ->setId($id)
33
            ->setTitle($title)
34
            ->setDescription($description)
35
            ->setValue($value)
0 ignored issues
show
Bug introduced by
$value of type string is incompatible with the type integer expected by parameter $value of Scrumban\Model\UserStory::setValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            ->setValue(/** @scrutinizer ignore-type */ $value)
Loading history...
36
            ->setStatus($status)
37
            ->setEstimatedTime($estimatedTime)
38
            ->setSpentTime($spentTime)
39
        ;
40
        if ($sprint !== null) {
41
            $userStory->setSprint($sprint);
42
        }
43
        $this->om->persist($userStory);
44
        $this->om->flush();
45
        $this->eventDispatcher->dispatch(UserStoryCreationEvent::NAME, new UserStoryCreationEvent($userStory));
46
        return $userStory;
47
    }
48
    
49
    public function updateUserStory(string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, Sprint $sprint = null, UserStory $userStory = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id 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 ignore-unused  annotation

49
    public function updateUserStory(/** @scrutinizer ignore-unused */ string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, Sprint $sprint = null, UserStory $userStory = null)

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...
50
    {
51
        $userStory
52
            ->setTitle($title)
0 ignored issues
show
Bug introduced by
The method setTitle() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            ->/** @scrutinizer ignore-call */ 
53
              setTitle($title)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            ->setDescription($description)
54
            ->setValue($value)
0 ignored issues
show
Bug introduced by
$value of type string is incompatible with the type integer expected by parameter $value of Scrumban\Model\UserStory::setValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
            ->setValue(/** @scrutinizer ignore-type */ $value)
Loading history...
55
            ->setStatus($status)
56
            ->setEstimatedTime($estimatedTime)
57
            ->setSpentTime($spentTime)
58
        ;
59
        if ($sprint !== null) {
60
            $userStory->setSprint($sprint);
61
        }
62
        $this->om->flush();
63
        $this->eventDispatcher->dispatch(UserStoryUpdateEvent::NAME, new UserStoryUpdateEvent($userStory));
0 ignored issues
show
Bug introduced by
It seems like $userStory can also be of type null; however, parameter $userStory of Scrumban\Event\UserStoryUpdateEvent::__construct() does only seem to accept Scrumban\Entity\UserStory, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        $this->eventDispatcher->dispatch(UserStoryUpdateEvent::NAME, new UserStoryUpdateEvent(/** @scrutinizer ignore-type */ $userStory));
Loading history...
64
    }
65
    
66
    public function getAll(): array
67
    {
68
        return $this->om->getRepository(UserStory::class)->findAll();
69
    }
70
    
71
    public function getSprintUserStories(Sprint $sprint, array $orderBy = null, int $page = null, int $limit = null): array
72
    {
73
        return $this->om->getRepository(UserStory::class)->findBy([
74
            'sprint' => $sprint
75
        ], $orderBy, $limit, $page * $limit);
76
    }
77
}