Code Duplication    Length = 60-60 lines in 3 locations

src/Queries/Mysql/Max.php 1 location

@@ 12-71 (lines=60) @@
9
/**
10
 * Manages a database select max query in Mysql databases.
11
 */
12
class Max extends Query
13
{
14
    use ExtendedSelectionTrait;
15
16
    protected $field;
17
18
    /**
19
     * Set the field name to maximize over.
20
     *
21
     * @param string $field
22
     *
23
     * @return self
24
     */
25
    public function field($field)
26
    {
27
        $this->field = $field;
28
29
        return $this;
30
    }
31
32
    /**
33
     * Run the query and return the value.
34
     * 
35
     * @return int
36
     */
37
    public function run()
38
    {
39
        $result = $this->__invoke()->fetch();
40
        $field = $this->table->{$this->field};
41
        
42
        return $field->dataFromDatabase($result[0]);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function __invoke()
49
    {
50
        $statement = $this->table->getDatabase()->execute((string) $this, $this->marks);
51
        $statement->setFetchMode(PDO::FETCH_NUM);
52
53
        return $statement;
54
    }
55
56
    /**
57
     * Build and return the query.
58
     *
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        $query = "SELECT MAX(`{$this->field}`) FROM `{$this->table->getName()}`";
64
65
        $query .= $this->fromToString();
66
        $query .= $this->whereToString();
67
        $query .= $this->limitToString();
68
69
        return $query;
70
    }
71
}
72

src/Queries/Mysql/Min.php 1 location

@@ 12-71 (lines=60) @@
9
/**
10
 * Manages a database select min query in Mysql databases.
11
 */
12
class Min extends Query
13
{
14
    use ExtendedSelectionTrait;
15
16
    protected $field;
17
18
    /**
19
     * Set the field name to maximize over.
20
     *
21
     * @param string $field
22
     *
23
     * @return self
24
     */
25
    public function field($field)
26
    {
27
        $this->field = $field;
28
29
        return $this;
30
    }
31
32
    /**
33
     * Run the query and return the value.
34
     * 
35
     * @return int
36
     */
37
    public function run()
38
    {
39
        $result = $this->__invoke()->fetch();
40
        $field = $this->table->{$this->field};
41
        
42
        return $field->dataFromDatabase($result[0]);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function __invoke()
49
    {
50
        $statement = $this->table->getDatabase()->execute((string) $this, $this->marks);
51
        $statement->setFetchMode(PDO::FETCH_NUM);
52
53
        return $statement;
54
    }
55
56
    /**
57
     * Build and return the query.
58
     *
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        $query = "SELECT MIN(`{$this->field}`) FROM `{$this->table->getName()}`";
64
65
        $query .= $this->fromToString();
66
        $query .= $this->whereToString();
67
        $query .= $this->limitToString();
68
69
        return $query;
70
    }
71
}
72

src/Queries/Mysql/Sum.php 1 location

@@ 12-71 (lines=60) @@
9
/**
10
 * Manages a database select sum query in Mysql databases.
11
 */
12
class Sum extends Query
13
{
14
    use ExtendedSelectionTrait;
15
16
    protected $field;
17
18
    /**
19
     * Set the field name to sum over.
20
     *
21
     * @param string $field
22
     *
23
     * @return self
24
     */
25
    public function field($field)
26
    {
27
        $this->field = $field;
28
29
        return $this;
30
    }
31
32
    /**
33
     * Run the query and return the value.
34
     * 
35
     * @return int
36
     */
37
    public function run()
38
    {
39
        $result = $this->__invoke()->fetch();
40
        $field = $this->table->{$this->field};
41
        
42
        return $field->dataFromDatabase($result[0]);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function __invoke()
49
    {
50
        $statement = $this->table->getDatabase()->execute((string) $this, $this->marks);
51
        $statement->setFetchMode(PDO::FETCH_NUM);
52
53
        return $statement;
54
    }
55
56
    /**
57
     * Build and return the query.
58
     *
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        $query = "SELECT SUM(`{$this->field}`) FROM `{$this->table->getName()}`";
64
65
        $query .= $this->fromToString();
66
        $query .= $this->whereToString();
67
        $query .= $this->limitToString();
68
69
        return $query;
70
    }
71
}
72