Completed
Push — master ( 8158f1...90d7fd )
by Konstantinos
11:17 queued 06:55
created

MatchController::showAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
use Symfony\Component\Form\FormError;
4
use Symfony\Component\HttpFoundation\RedirectResponse;
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\StreamedResponse;
7
8
class MatchController extends CRUDController
9
{
10
    /**
11
     * Whether the last edited match has had its ELO changed, requiring an ELO
12
     * recalculation
13
     *
14
     * This is useful so that a confirmation form is shown, asking the user if
15
     * they want to recalculate ELOs
16
     *
17
     * @var bool
18
     */
19
    public $recalculateNeeded = false;
20
21
    public function listAction(Request $request, Player $me, Team $team = null, $type = null)
22
    {
23
        $qb = $this->getQueryBuilder();
24
25
        $currentPage = $request->query->get('page', 1);
26
27
        $query = $qb->sortBy('time')->reverse()
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class QueryBuilder as the method with() does only exist in the following sub-classes of QueryBuilder: MatchQueryBuilder. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
28
               ->with($team, $type)
29
               ->limit(50)->fromPage($currentPage);
30
31
        $matches = $query->getModels($fast = true);
32
33
        foreach ($matches as $match) {
34
            // Don't show wrong labels for matches
35
            $match->getOriginalTimestamp()->setTimezone($me->getTimezone());
36
        }
37
38
        return array(
39
            "matches"     => $matches,
40
            "team"        => $team,
41
            "currentPage" => $currentPage,
42
            "totalPages"  => $qb->countPages()
43
        );
44
    }
45
46 1
    public function showAction(Match $match)
47
    {
48 1
        return array("match" => $match);
49
    }
50
51 1 View Code Duplication
    public function createAction(Player $me)
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...
52
    {
53
        return $this->create($me, function (Match $match) use ($me) {
54 1
            if ($me->canEdit($match)
55 1
                && $match->isOfficial()
56 1
                && (!$match->getTeamA()->isLastMatch($match)
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method isLastMatch() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
57 1
                || !$match->getTeamB()->isLastMatch($match))
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method isLastMatch() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
58
            ) {
59
                $url = Service::getGenerator()->generate('match_recalculate', array(
60
                    'match' => $match->getId(),
61
                ));
62
63
                return new RedirectResponse($url);
64
            }
65 1
        });
66
    }
67
68
    public function deleteAction(Player $me, Match $match)
69
    {
70 View Code Duplication
        return $this->delete($match, $me, function () use ($match, $me) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
71
            if ($match->getTeamA()->isLastMatch($match)
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method isLastMatch() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
72
                && $match->getTeamB()->isLastMatch($match)) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method isLastMatch() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
73
                $match->resetELOs();
74
            } elseif ($me->canEdit($match)) {
75
                $url = Service::getGenerator()->generate('match_recalculate', array(
76
                    'match' => $match->getId(),
77
                ));
78
79
                return new RedirectResponse($url);
80
            }
81
        });
82
    }
83
84
    public function editAction(Player $me, Match $match)
85
    {
86
        // TODO: Generating this response is unnecessary
87
        $response = $this->edit($match, $me, "match");
88
89 View Code Duplication
        if ($this->recalculateNeeded && $match->isOfficial()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
90
            // Redirect to a confirmation form if we are assigning a new leader
91
            $url = Service::getGenerator()->generate('match_recalculate', array(
92
                'match' => $match->getId(),
93
            ));
94
95
            return new RedirectResponse($url);
96
        }
97
98
        return $response;
99
    }
100
101
    public function recalculateAction(Player $me, $match)
102
    {
103
        $match = Match::get($match); // get a match even if it's deleted
104
105
        if (!$me->canEdit($match)) {
106
            throw new ForbiddenException("You are not allowed to edit that match.");
107
        }
108
109
        if (!$match->isOfficial()) {
110
            throw new BadRequestException("You can't recalculate ELO history for a special match.");
111
        }
112
113
        return $this->showConfirmationForm(function () use ($match) {
114
            $response = new StreamedResponse();
115
            $response->headers->set('Content-Type', 'text/plain');
116
            $response->setCallback(function () use ($match) {
117
                $this->recalculate($match);
118
            });
119
            $response->send();
120
        }, "Do you want to recalculate ELO history for all teams and matches after the specified match?",
121
            "ELO history recalculated",
122
            "Recalculate ELOs",
123
            function () use ($match) {
124
                if ($match->isDeleted()) {
125
                    return new RedirectResponse($match->getURL('list'));
126
                }
127
128
                return new RedirectResponse($match->getURL('show'));
129
            },
130
            "Match/recalculate.html.twig",
131
            $noButton = true
132
        );
133
    }
134
135
    /**
136
     * Recalculates match history for all teams and matches
137
     *
138
     * Recalculation is done as follows:
139
     * 1. A match is chosen as a starting point - it's stored old team ELOs are
140
     *    considered correct
141
     * 2. Team ELOs are reset to their values at the starting point
142
     * 3. Each match that occurred since the first specified match has its ELO
143
     *    recalculated based on the current team values, and the new match data
144
     *    and team ELOs are stored in the database
145
     *
146
     * @param Match $match The first match
147
     */
148
    private function recalculate(Match $match)
149
    {
150
        try {
151
            // Commented out to prevent ridiculously large recalculations
152
            //set_time_limit(0);
153
154
            $query = Match::getQueryBuilder()
155
                ->where('status')->notEquals('deleted')
156
                ->where('type')->equals(Match::OFFICIAL)
157
                ->where('time')->isAfter($match->getTimestamp(), $inclusive = true)
158
                ->sortBy('time');
159
160
            /** @var Match[] $matches */
161
            $matches = $query->getModels($fast = true);
162
163
            // Send the total count to client-side javascript
164
            $this->log(count($matches) . "\n");
165
166
            // Start a transaction so tables are locked and we don't stay with
167
            // messed up data if something goes wrong
168
            Database::getInstance()->startTransaction();
169
170
            $teamsReset = [];
171
172
            // Reset match teams, in case the selected match is deleted and does
173
            // not show up in the list of matches to recalculate
174
            $match->getTeamA()->setElo($match->getTeamAEloOld());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method setElo() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
175
            $match->getTeamB()->setElo($match->getTeamBEloOld());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method setElo() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
176
            $teamsReset[ $match->getTeamA()->getId() ] = true;
177
            $teamsReset[ $match->getTeamB()->getId() ] = true;
178
179
            foreach ($matches as $i => $match) {
180
                // Reset teams' ELOs if they haven't been reset already
181 View Code Duplication
                if (!isset($teamsReset[ $match->getTeamA()->getId() ])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
182
                    $teamsReset[ $match->getTeamA()->getId() ] = true;
183
                    $match->getTeamA()->setElo($match->getTeamAEloOld());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method setElo() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
184
                }
185 View Code Duplication
                if (!isset($teamsReset[ $match->getTeamB()->getId() ])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
186
                    $teamsReset[ $match->getTeamB()->getId() ] = true;
187
                    $match->getTeamB()->setElo($match->getTeamBEloOld());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TeamInterface as the method setElo() does only exist in the following implementations of said interface: Team.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
188
                }
189
190
                $match->recalculateElo();
191
192
                // Send an update to the client-side javascript, so that a
193
                // progress bar can be updated
194
                $this->log("m");
195
            }
196
        } catch (Exception $e) {
197
            Database::getInstance()->rollback();
198
            Database::getInstance()->finishTransaction();
199
            throw $e;
200
        }
201
202
        Database::getInstance()->finishTransaction();
203
204
        $this->log("\n\nCalculation successful\n");
205
    }
206
207
    /**
208
     * Echo a string and flush the buffers
209
     *
210
     * Useful for streamed AJAX responses
211
     *
212
     * @param string $string The string to echo
213
     */
214
    private function log($string)
215
    {
216
        echo $string;
217
        ob_flush();
218
        flush();
219
    }
220
221
    /**
222
     * {@inheritdoc}
223
     */
224 1
    protected function getMessages($type, $name = '')
225
    {
226 1
        $messages = parent::getMessages($type, $name);
227
228
        // Don't show the match info on the successful create/edit message
229 1
        foreach ($messages as &$action) {
230 1
            foreach ($action as &$status) {
231 1
                if (isset($status['named'])) {
232 1
                    $status['named'] = $status['unnamed'];
233
                }
234
            }
235
        }
236
237 1
        return $messages;
238
    }
239
240 1
    protected function validate($form)
241
    {
242
        // Make sure that two different teams participated in a match, i.e. a team
243
        // didn't match against itself
244 1
        $firstTeam  = $form->get('first_team')->get('team')->getData();
245 1
        $secondTeam = $form->get('second_team')->get('team')->getData();
246
247 1
        if (!$firstTeam || !$secondTeam) {
248
            return;
249
        }
250
251 1
        if ($firstTeam->isSameAs($secondTeam)) {
252 1
            $message = "You can't report a match where a team played against itself!";
253 1
            $form->addError(new FormError($message));
254
        }
255
256 1
        foreach (array('first_team', 'second_team') as $team) {
257 1
            $input = $form->get($team)->get('team');
258
259 1
            if ($form->get('type')->getData() == Match::OFFICIAL) {
260 1
                if ($input->getData() instanceof ColorTeam) {
261
                    $message = "Please enter a valid team for an official match.";
262 1
                    $input->addError(new FormError($message));
263
                }
264
            } else {
265 1
                if (!$input->getData() instanceof ColorTeam) {
266
                    $message = "Please enter a team color for fun and special matches.";
267 1
                    $input->addError(new FormError($message));
268
                }
269
            }
270
        }
271 1
    }
272
273
    protected function validateEdit($form, $match)
274
    {
275
        if ($match->isOfficial() && $form->get('type')->getData() !== Match::OFFICIAL) {
276
            $message = "You cannot change this match's type.";
277
            $form->get('type')->addError(new FormError($message));
278
        } elseif (!$match->isOfficial() && $form->get('type')->getData() === Match::OFFICIAL) {
279
            $message = "You can't make this an official match.";
280
            $form->get('type')->addError(new FormError($message));
281
        }
282
    }
283
}
284