1 | <?php |
||||||
2 | |||||||
3 | namespace Scrumban\Manager; |
||||||
4 | |||||||
5 | use Scrumban\Registry\RegistryInterface; |
||||||
6 | use Scrumban\Gateway\GatewayInterface; |
||||||
7 | |||||||
8 | use Scrumban\Utils\CardHelper; |
||||||
9 | |||||||
10 | use Scrumban\Utils\PlusForTrelloHelper; |
||||||
11 | |||||||
12 | use Scrumban\Entity\Sprint; |
||||||
13 | |||||||
14 | class BoardManager |
||||||
15 | { |
||||||
16 | /** @var RegistryInterface **/ |
||||||
17 | protected $registry; |
||||||
18 | /** @var GatewayInterface **/ |
||||||
19 | protected $gateway; |
||||||
20 | /** @var UserStoryManager **/ |
||||||
21 | protected $userStoryManager; |
||||||
22 | /** @var SprintManager **/ |
||||||
23 | protected $sprintManager; |
||||||
24 | /** @var bool **/ |
||||||
25 | public $hasPlusForTrello; |
||||||
26 | |||||||
27 | public function __construct(RegistryInterface $registry, GatewayInterface $gateway, UserStoryManager $userStoryManager, SprintManager $sprintManager) |
||||||
28 | { |
||||||
29 | $this->registry = $registry; |
||||||
30 | $this->gateway = $gateway; |
||||||
31 | $this->userStoryManager = $userStoryManager; |
||||||
32 | $this->sprintManager = $sprintManager; |
||||||
33 | } |
||||||
34 | |||||||
35 | public function sync($boardName) |
||||||
36 | { |
||||||
37 | if (($boardData = $this->registry->getBoard($boardName)) === null) { |
||||||
38 | throw new \InvalidArgumentException('No board is configured for the given name'); |
||||||
39 | } |
||||||
40 | $this->init(); |
||||||
41 | $columns = $this->gateway->getBoardColumns($boardData['id']); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
42 | $currentSprint = $this->sprintManager->getCurrentSprint(); |
||||||
43 | |||||||
44 | foreach ($columns as $columnData) { |
||||||
45 | yield "comment" => "Scanning column {$columnData['name']}..."; |
||||||
46 | if (($column = $this->registry->getColumn(CardHelper::slugify($columnData['name']))) === null) { |
||||||
47 | continue; |
||||||
48 | } |
||||||
49 | $messages = $this->processColumnCards($columnData['id'], $column, $currentSprint); |
||||||
50 | foreach($messages as $type => $message) { |
||||||
51 | yield $type => $message; |
||||||
52 | } |
||||||
53 | yield "info" => "Column {$columnData['name']} has been synchronized"; |
||||||
54 | } |
||||||
55 | } |
||||||
56 | |||||||
57 | protected function init() |
||||||
58 | { |
||||||
59 | $this->registry->storeUserStories($this->userStoryManager->getAll()); |
||||||
0 ignored issues
–
show
The method
storeUserStories() does not exist on Scrumban\Registry\RegistryInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Scrumban\Registry\RegistryInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
60 | } |
||||||
61 | |||||||
62 | protected function processColumnCards(string $columnId, array $column, Sprint $sprint = null) |
||||||
63 | { |
||||||
64 | $cards = $this->gateway->getColumnCards($columnId); |
||||||
0 ignored issues
–
show
The method
getColumnCards() does not exist on Scrumban\Gateway\GatewayInterface . It seems like you code against a sub-type of Scrumban\Gateway\GatewayInterface such as Scrumban\Gateway\TrelloGateway .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
65 | yield "info" => count($cards) . " cards to synchronize with status {$column['status']}"; |
||||||
66 | foreach ($cards as $card) { |
||||||
67 | $titleParts = explode('|', $card['name']); |
||||||
68 | $extraData = isset($titleParts[1]) ? trim($titleParts[1]): ''; |
||||||
69 | |||||||
70 | $estimations = $this->getCardEstimations($card, $extraData); |
||||||
71 | |||||||
72 | $method = |
||||||
73 | (($userStory = $this->registry->getUserStory($card['id'])) === null) |
||||||
0 ignored issues
–
show
The method
getUserStory() does not exist on Scrumban\Registry\RegistryInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Scrumban\Registry\RegistryInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
74 | ? 'createUserStory' |
||||||
75 | : 'updateUserStory' |
||||||
76 | ; |
||||||
77 | $this->userStoryManager->{$method}( |
||||||
78 | $card['id'], |
||||||
79 | trim($titleParts[0]), |
||||||
80 | $card['desc'], |
||||||
81 | (!empty($extraData)) ? CardHelper::extractValue($extraData) : 0, |
||||||
82 | $column['status'], |
||||||
83 | $estimations['estimated'], |
||||||
84 | $estimations['spent'], |
||||||
85 | CardHelper::extractCreationDate($card['id']), |
||||||
86 | CardHelper::isInCurrentSprint($column['status']) ? $sprint : null, |
||||||
87 | $userStory |
||||||
88 | ); |
||||||
89 | } |
||||||
90 | } |
||||||
91 | |||||||
92 | protected function getCardEstimations(array $card, string $extraData): array |
||||||
93 | { |
||||||
94 | if ($this->hasPlusForTrello !== true || empty($extraData)) { |
||||||
95 | return [ |
||||||
96 | 'estimated' => CardHelper::extractEstimatedTime($extraData), |
||||||
97 | 'spent' => CardHelper::extractSpentTime($extraData) |
||||||
98 | ]; |
||||||
99 | } |
||||||
100 | if ($card['badges']['comments'] === 0) { |
||||||
101 | return ['estimated' => 0, 'spent' => 0]; |
||||||
102 | } |
||||||
103 | return PlusForTrelloHelper::extractEstimations($this->gateway->getCardComments($card['id'])); |
||||||
0 ignored issues
–
show
The method
getCardComments() does not exist on Scrumban\Gateway\GatewayInterface . It seems like you code against a sub-type of Scrumban\Gateway\GatewayInterface such as Scrumban\Gateway\TrelloGateway .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
104 | } |
||||||
105 | } |