Issues (18)

Manager/UserStoryManager.php (6 issues)

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, \DateTime $createdAt, 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
$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
            ->setCreatedAt($createdAt)
40
        ;
41
        if ($sprint !== null) {
42
            $userStory->setSprint($sprint);
43
        }
44
        $this->om->persist($userStory);
45
        $this->om->flush();
46
        $this->eventDispatcher->dispatch(UserStoryCreationEvent::NAME, new UserStoryCreationEvent($userStory));
47
        return $userStory;
48
    }
49
    
50
    public function updateUserStory(string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, \DateTime $createdAt, Sprint $sprint = null, UserStory $userStory = null)
0 ignored issues
show
The parameter $createdAt 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

50
    public function updateUserStory(string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, /** @scrutinizer ignore-unused */ \DateTime $createdAt, 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...
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

50
    public function updateUserStory(/** @scrutinizer ignore-unused */ string $id, string $title, string $description, string $value, string $status, float $estimatedTime, float $spentTime, \DateTime $createdAt, 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...
51
    {
52
        $userStory
53
            ->setTitle($title)
0 ignored issues
show
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

53
            ->/** @scrutinizer ignore-call */ 
54
              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...
54
            ->setDescription($description)
55
            ->setValue($value)
0 ignored issues
show
$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

55
            ->setValue(/** @scrutinizer ignore-type */ $value)
Loading history...
56
            ->setStatus($status)
57
            ->setEstimatedTime($estimatedTime)
58
            ->setSpentTime($spentTime)
59
        ;
60
        if ($sprint !== null) {
61
            $userStory->setSprint($sprint);
62
        }
63
        $this->om->flush();
64
        $this->eventDispatcher->dispatch(UserStoryUpdateEvent::NAME, new UserStoryUpdateEvent($userStory));
0 ignored issues
show
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

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