nieMoznaDodacKolejnegoUbezpieczeniaDoSamochoduKtoregoDataRozpoczeciaBedzieWczesniejNizDataKoncaPoprzedniego()   B
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 14
nc 5
nop 2
1
<?php
2
3
namespace Madkom\RegistryApplication\Domain\CarManagement\Behat;
4
5
use Behat\Behat\Context\Context;
6
use Behat\Behat\Context\SnippetAcceptingContext;
7
use Behat\Behat\Tester\Exception\PendingException;
8
use Behat\Gherkin\Node\TableNode;
9
use Madkom\RegistryApplication\Application\CarManagement\Command\Insurance\AddInsuranceCommand;
10
use Madkom\RegistryApplication\Application\CarManagement\Command\Insurance\AddInsuranceDocumentCommand;
11
use Madkom\RegistryApplication\Application\CarManagement\DocumentDTO;
12
use Madkom\RegistryApplication\Application\CarManagement\InsuranceDTO;
13
use Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException;
14
use Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\NonexistentInsuranceException;
15
use Madkom\RegistryApplication\Domain\CarManagement\Insurances\Exceptions\DuplicatedInsuranceException;
16
17
class InsuranceManagerContext extends ContextRepositoryInterface implements Context, SnippetAcceptingContext
0 ignored issues
show
Deprecated Code introduced by
The interface Behat\Behat\Context\SnippetAcceptingContext has been deprecated with message: will be removed in 4.0. Use --snippets-for CLI option instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
18
{
19
    /**
20
     * @Then chciałbym do samochodu :carId dodać ubezpieczenie o następujących danych:
21
     */
22 View Code Duplication
    public function chcialbymDoSamochoduDodacUbezpieczenieONastepujacychDanych($carId, TableNode $table)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $insurance = $table->getHash();
25
26
        foreach ($insurance as $item) {
27
            $dto = new InsuranceDTO($item['id'],
28
                                    $item['type'],
29
                                    $item['dateFrom'],
30
                                    $item['dateTo'],
31
                                    $item['insurerId']
32
            );
33
34
            $newInsurance = AddInsuranceCommand::add(self::$carRepository, $carId, $dto);
35
            $newInsurance->execute();
36
        }
37
    }
38
39
    /**
40
     * @Then nie można dodać ubezpieczenia do samochodu :carId, gdy różnica między dateFrom i dateTo jest inna niż jeden rok:
41
     *
42
     * @throws \Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException
43
     * @throws \InvalidArgumentException
44
     */
45 View Code Duplication
    public function nieMoznaDodacUbezpieczeniaDoSamochoduGdyRoznicaMiedzyDateFromIDateToJestInnaNizJedenRok($carId, TableNode $table)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $insurance = $table->getHash();
48
49
        foreach ($insurance as $item) {
50
            $dto = new InsuranceDTO($item['id'],
51
                                    $item['type'],
52
                                    $item['dateFrom'],
53
                                    $item['dateTo'],
54
                                    $item['insurerId']
55
            );
56
57
            $newInsurance = AddInsuranceCommand::add(self::$carRepository, $carId, $dto);
58
59
            try {
60
                $newInsurance->execute();
61
                throw new \InvalidArgumentException('W tym teście spodziewano się wyjątku InvalidDatesException, ale go nie otrzymano');
62
            } catch (InvalidDatesException $datesException) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
63
            }
64
        }
65
    }
66
67
    /**
68
     * @Then nie można dodać kolejnego ubezpieczenia do samochodu :carId, którego data rozpoczęcia będzie wcześniej niż data końca poprzedniego:
69
     * @Then nie można dodać kolejnego ubezpieczenia do samochodu :carId, którego data rozpoczęcia będzie później niż data końca poprzedniego:
70
     *
71
     * @throws \Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\InvalidDatesException
72
     * @throws \InvalidArgumentException
73
     */
74 View Code Duplication
    public function nieMoznaDodacKolejnegoUbezpieczeniaDoSamochoduKtoregoDataRozpoczeciaBedzieWczesniejNizDataKoncaPoprzedniego($carId, TableNode $table)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $insurance = $table->getHash();
77
78
        foreach ($insurance as $item) {
79
            $dto = new InsuranceDTO($item['id'],
80
                                    $item['type'],
81
                                    $item['dateFrom'],
82
                                    $item['dateTo'],
83
                                    $item['insurerId']
84
            );
85
86
            $newInsurance = AddInsuranceCommand::add(self::$carRepository, $carId, $dto);
87
88
            try {
89
                $newInsurance->execute();
90
                throw new \InvalidArgumentException('W tym teście spodziewano się wyjątku InvalidDatesException, ale go nie otrzymano');
91
            } catch (InvalidDatesException $datesException) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
92
            } catch (DuplicatedInsuranceException $duplicatesException) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
93
            }
94
        }
95
    }
96
97
    /**
98
     * @Given w repozytorium dodane ubezpieczenia
99
     */
100
    public function wRepozytoriumDodaneUbezpieczenia()
101
    {
102
        $car = self::$carRepository->find(1);
103
        $car->getInsurances();
0 ignored issues
show
Unused Code introduced by
The call to the method Madkom\RegistryApplicati...nt\Car::getInsurances() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
104
    }
105
106
    /**
107
     * @Then chciałbym do istniejącego ubezpieczenia dodać plik:
108
     * @Then chciałbym dodać do istniejącego ubezpieczenia kolejny plik:
109
     * @Then chciałbym aby nie było możliwe dodanie pliku do nieistniejącego ubezpieczenia:
110
     */
111
    public function chcialbymDoIstniejacegoUbezpieczeniaDodacPlik(TableNode $table)
112
    {
113
        foreach ($table as $item) {
114
            $dto = new DocumentDTO($item['fileId'],
115
                                    $item['title'],
116
                                    $item['description'],
117
                                    $item['source']
118
            );
119
120
            $newInsuranceDocument = new AddInsuranceDocumentCommand(self::$carRepository,
121
                                                                    $item['carId'],
122
                                                                    $item['insuranceId'],
123
                                                                    $dto
124
            );
125
126
            try {
127
                $newInsuranceDocument->execute();
128
            } catch (NonexistentInsuranceException $nonexistent) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
129
            }
130
        }
131
    }
132
133
    /**
134
     * @Then chciałbym aby dla samochodu :carId istniały ubezpieczenia:
135
     */
136
    public function chcialbymAbyDlaSamochoduIstnialyUbezpieczenia($carId, TableNode $table)
137
    {
138
        $car = self::$carRepository->find($carId);
139
        $insurances = $car->getInsurances();
0 ignored issues
show
Unused Code introduced by
$insurances is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
140
141
        $insurancesId = $table->getHash();
142
143
        foreach ($insurancesId as $key => $value) {
0 ignored issues
show
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
144
        }
145
    }
146
147
    /**
148
     * @Then chciałbym aby dla samochodu :arg1 nie istniały ubezpieczenia o :arg2:
149
     */
150
    public function chcialbymAbyDlaSamochoduNieIstnialyUbezpieczeniaO($arg1, $arg2, TableNode $table)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arg2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
151
    {
152
        throw new PendingException();
153
    }
154
155
    /**
156
     * @Then chciałbym aby w samochodzie :arg1 było ubezpieczenie o id :arg2
157
     */
158
    public function chcialbymAbyWSamochodzieByloUbezpieczenieOId($arg1, $arg2)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arg2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
159
    {
160
        throw new PendingException();
161
    }
162
163
    /**
164
     * @Then chciałbym aby w samochodzie :arg1 nie było ubezpieczenia o id :arg2
165
     */
166
    public function chcialbymAbyWSamochodzieNieByloUbezpieczeniaOId($arg1, $arg2)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arg2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
167
    {
168
        throw new PendingException();
169
    }
170
171
    /**
172
     * @Then chciałbym aby nie było możliwe dodanie kolejnego pliku o id :arg1
173
     */
174
    public function chcialbymAbyNieByloMozliweDodanieKolejnegoPlikuOId($arg1)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
175
    {
176
        throw new PendingException();
177
    }
178
179
    /**
180
     * @Then chciałbym aby nie była możliwa podmiana istniejącego pliku :arg1
181
     */
182
    public function chcialbymAbyNieBylaMozliwaPodmianaIstniejacegoPliku($arg1)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
183
    {
184
        throw new PendingException();
185
    }
186
187
    /**
188
     * @Then chciałbym usunąć plik :arg1
189
     */
190
    public function chcialbymUsunacPlik($arg1)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
191
    {
192
        throw new PendingException();
193
    }
194
195
    /**
196
     * @Then chciałbym aby nie było możliwe pobranie pliku :arg1
197
     */
198
    public function chcialbymAbyNieByloMozliwePobraniePliku($arg1)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
199
    {
200
        throw new PendingException();
201
    }
202
203
    /**
204
     * @Then chciałbym aby nie było możliwe usunięcie pliku :arg1
205
     */
206
    public function chcialbymAbyNieByloMozliweUsunieciePliku($arg1)
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
207
    {
208
        throw new PendingException();
209
    }
210
}
211