Completed
Push — master ( 62da74...554a7a )
by Anton
11s
created

Table::getImagesByUserId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/skeleton
5
 */
6
7
/**
8
 * @namespace
9
 */
10
namespace Application\Media;
11
12
use Application\Exception;
13
use Bluz\Proxy\Auth;
14
15
/**
16
 * Table
17
 *
18
 * @package  Application\Media
19
 *
20
 * @method   static Row findRow($primaryKey)
21
 * @method   static Row findRowWhere($whereList)
22
 */
23
class Table extends \Bluz\Db\Table
24
{
25
    /**
26
     * Table
27
     *
28
     * @var string
29
     */
30
    protected $table = 'media';
31
32
    /**
33
     * Primary key(s)
34
     * @var array
35
     */
36
    protected $primary = array('id');
37
38
    /**
39
     * Get images of current user
40
     *
41
     * @return Row[]
42
     * @throws Exception
43
     */
44 1
    public function getImages()
45
    {
46
        /** @var Row $user */
47 1
        if (!$user = Auth::getIdentity()) {
48
            throw new Exception('User not found');
49
        }
50
51 1
        return $this->getImagesByUserId($user->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Bluz\Auth\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
52
    }
53
54
    /**
55
     * Get images by owner
56
     *
57
     * @param  integer $id
58
     * @return Row[]
59
     */
60 1
    public function getImagesByUserId($id)
61
    {
62 1
        return self::select()
63 1
            ->where('type LIKE (?)', 'image/%')
64 1
            ->andWhere('userId = ?', $id)
65 1
            ->execute();
66
    }
67
}
68