Completed
Push — feature/select_existing_custom... ( a1e51a )
by Laurent
01:57
created

ClassifyFlightHandler::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
4
namespace flightlog\command;
5
6
use Bbcvols;
7
use CommandHandlerInterface;
8
use CommandInterface;
9
use Conf;
10
use stdClass;
11
use Translate;
12
use User;
13
14
/**
15
 * @package flightlog\command
16
 */
17
final class ClassifyFlightHandler implements CommandHandlerInterface
18
{
19
20
    /**
21
     * @var \DoliDB
22
     */
23
    private $db;
24
25
    /**
26
     * @var Conf
27
     */
28
    private $conf;
29
30
    /**
31
     * @var Translate
32
     */
33
    private $langs;
34
35
    /**
36
     * @var User
37
     */
38
    private $user;
39
40
    /**
41
     * @param \DoliDB $db
42
     * @param stdClass $conf
43
     * @param Translate $langs
44
     * @param User $user
45
     */
46
    public function __construct(\DoliDB $db, Conf $conf, Translate $langs, User $user)
47
    {
48
        $this->db = $db;
49
        $this->conf = $conf;
50
        $this->langs = $langs;
51
        $this->user = $user;
52
    }
53
54
    /**
55
     * @param CommandInterface|ClassifyFlight $command
56
     *
57
     * @throws \Exception
58
     */
59
    public function handle(CommandInterface $command)
60
    {
61
        /** @var ClassifyFlight $command */
62
63
        $projectId = 'NULL';
64
        if (!empty($command->getProjectId())) {
65
            $projectId = $command->getProjectId();
66
        }
67
68
        $result = $this->db->query(sprintf('UPDATE %s%s SET fk_project=%s WHERE rowid=%s', MAIN_DB_PREFIX,
69
            Bbcvols::$table, $projectId, $command->getFlightId()));
70
        if (!$result) {
71
            throw new \Exception($this->db->error());
72
        }
73
    }
74
}