Completed
Pull Request — 2.x (#43)
by jake
02:49 queued 50s
created

Img   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 42.86%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 1
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 32
ccs 3
cts 7
cp 0.4286
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Html\Helper;
10
11
/**
12
 *
13
 * Helper to generate an `<img ... />` tag.
14
 *
15
 * @package Aura.Html
16
 *
17
 */
18
class Img extends AbstractHelper
19
{
20
    /**
21
     *
22
     * Returns an <img ... /> tag.
23
     *
24
     * If an "alt" attribute is not specified, will add it from the
25
     * image basename.
26
     *
27
     * @param string $src The href to the image source.
28
     *
29
     * @param array $attr Additional attributes for the tag.
30
     *
31
     * @return string An <img ... /> tag.
32
     *
33
     * @todo Add automated height/width calculation?
34
     *
35
     */
36 1
    public function __invoke($src, array $attr = array())
37
    {
38
        $base = array(
39
            'src' => $src,
40 1
            'alt' => basename($src),
41
        );
42
43
        unset($attr['src']);
44
45
        $attr = array_merge($base, $attr);
46
47
        return $this->void('img', $attr);
48 1
    }
49
}
50