Passed
Push — feature/more-precise-NoBeanFou... ( 7d6857 )
by Kevin
10:05
created

NoBeanFoundException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
c 0
b 0
f 0
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTableName() 0 3 1
A missFilterRecord() 0 3 1
A getPrimaryKeys() 0 3 1
A missPrimaryKeyRecord() 0 11 1
A getClassName() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TheCodingMachine\TDBM;
5
6
/**
7
 * An exception thrown if no rows are returned when TDBMService->findObjectOrFail is called.
8
 */
9
class NoBeanFoundException extends TDBMException
10
{
11
12
    private string $tableName;
13
    private string $className;
14
15
    /**
16
     * @var string[]
17
     */
18
    private array $primaryKeys;
19
20
    public static function missPrimaryKeyRecord(string $tableName, array $primaryKeys, string $className, $previous) : self
21
    {
22
        $primaryKeysStringified = implode(' and ', array_map(function ($key, $value) {
23
            return "'".$key."' = ".$value;
24
        }, array_keys($primaryKeys), $primaryKeys));
25
        $exception = new self("No result found for query on table '".$tableName."' for ".$primaryKeysStringified, 0, $previous);
26
        $exception->tableName = $tableName;
27
        $exception->primaryKeys = $primaryKeys;
28
        $exception->className = $className;
29
30
        return $exception;
31
    }
32
33
    public static function missFilterRecord(string $tableName) : self
34
    {
35
        return new self("No result found for query on table '".$tableName."'");
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getTableName(): string
42
    {
43
        return $this->tableName;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getClassName(): string
50
    {
51
        return $this->className;
52
    }
53
54
    /**
55
     * @return string[]
56
     */
57
    public function getPrimaryKeys(): array
58
    {
59
        return $this->primaryKeys;
60
    }
61
62
}
63