Ajde_Resource_FileIcon::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Code from CambioCMS project
5
 * @link http://code.google.com/p/cambiocms/source/browse/trunk/cms/includes/602_html.image.php
6
 */
7
8
class Ajde_Resource_FileIcon extends Ajde_Resource
9
{
10
    private $_iconCdn = 'http://p.yusukekamiyamane.com/icons/search/fugue/icons/%s.png';
11
    private $_iconDictionary = [
12
        '*'    => 'document',
13
        'jpg'  => 'document-image',
14
        'gif'  => 'document-image',
15
        'png'  => 'document-image',
16
        'bmp'  => 'document-image',
17
        'xls'  => 'document-excel',
18
        'xlsx' => 'document-excel',
19
        'ppt'  => 'document-powerpoint',
20
        'pptx' => 'document-powerpoint',
21
        'doc'  => 'document-word',
22
        'docx' => 'document-word',
23
        'pdf'  => 'document-pdf',
24
        'mp3'  => 'document-music',
25
        'wav'  => 'document-music',
26
        'zip'  => 'folder-zipper',
27
        'mpg'  => 'film',
28
        'avi'  => 'film',
29
    ];
30
31
    public function __construct($fileExtension)
32
    {
33
        $this->set('extension', $fileExtension);
34
    }
35
36
    public static function _($fileExtension)
37
    {
38
        $tmp = new self($fileExtension);
39
40
        return (string) $tmp;
41
    }
42
43
    public function getFilename()
44
    {
45
        return $this->getLinkUrl();
46
    }
47
48
    public function __toString()
49
    {
50
        return $this->getFilename();
51
    }
52
53
    protected function getLinkUrl()
54
    {
55
        return sprintf($this->_iconCdn,
56
            isset($this->_iconDictionary[$this->getExtension()]) ? $this->_iconDictionary[$this->getExtension()] : $this->_iconDictionary['*']);
0 ignored issues
show
Documentation Bug introduced by
The method getExtension does not exist on object<Ajde_Resource_FileIcon>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
57
    }
58
}
59