Passed
Push — search ( bdb480...5e7f6e )
by Simon
17:14 queued 07:17
created

UserDomain   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 23
c 1
b 0
f 0
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 26 3
A setDomain() 0 3 1
A setUser() 0 3 1
A getUser() 0 3 1
A getDomain() 0 3 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\DataObjects;
10
11
use Exception;
12
use Waca\DataObject;
13
14
class UserDomain extends DataObject
15
{
16
    /** @var int */
17
    private $user;
18
19
    /** @var int */
20
    private $domain;
21
22
    public function save()
23
    {
24
        if ($this->isNew()) {
25
            // insert
26
            $statement = $this->dbObject->prepare(<<<SQL
27
                INSERT INTO userdomain (
28
                    user, domain
29
                ) VALUES (
30
                    :user, :domain
31
                );
32
SQL
33
            );
34
35
            $statement->bindValue(":user", $this->user);
36
            $statement->bindValue(":domain", $this->domain);
37
38
            if ($statement->execute()) {
39
                $this->id = (int)$this->dbObject->lastInsertId();
40
            }
41
            else {
42
                throw new Exception($statement->errorInfo());
0 ignored issues
show
Bug introduced by
$statement->errorInfo() of type array is incompatible with the type string expected by parameter $message of Exception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
                throw new Exception(/** @scrutinizer ignore-type */ $statement->errorInfo());
Loading history...
43
            }
44
        }
45
        else {
46
            // insert / delete only, no updates please.
47
            throw new Exception('Updating domain membership is not available');
48
        }
49
    }
50
51
    /**
52
     * @return int
53
     */
54
    public function getUser(): int
55
    {
56
        return $this->user;
57
    }
58
59
    /**
60
     * @param int $user
61
     */
62
    public function setUser(int $user): void
63
    {
64
        $this->user = $user;
65
    }
66
67
    /**
68
     * @return int
69
     */
70
    public function getDomain(): int
71
    {
72
        return $this->domain;
73
    }
74
75
    /**
76
     * @param int $domain
77
     */
78
    public function setDomain(int $domain): void
79
    {
80
        $this->domain = $domain;
81
    }
82
83
84
}