Marker   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 12
Bugs 0 Features 1
Metric Value
wmc 2
eloc 7
c 12
b 0
f 1
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A a() 0 5 1
A img() 0 7 1
1
<?php
2
3
/**
4
  * HTML generator
5
  * Marker, hommage to Christian François Bouche-Villeneuve aka Chris Marker
6
  */
7
8
declare(strict_types=1);
9
10
namespace HexMakina\Marker;
11
12
class Marker extends Element
13
{
14
    /**
15
      * ? smoother write
16
      * Marker::img('path/to/img.jpg', 'An alternative text', ['width' => 34, 'height' => 34])
17
      * than
18
      * Element::img(null, ['src' => 'path/to/img.jpg', 'alt' => 'An alternative text', 'width' => 34, 'height' => 34])
19
      */
20
    public static function img(string $src, string $alt, array $attributes = [], $formatter=null): Element
21
    {
22
        $attributes['src'] ??= $src;
23
        $attributes['alt'] ??= $alt;
24
        $attributes['title'] ??= $alt;
25
26
        return new Element('img', null,$attributes, $formatter);
27
    }
28
29
    /**
30
      * ? makes more sense to write
31
      * Marker::a('controller/task/id', 'Click here', ['class' => 'nav'])
32
      * than
33
      * Marker::a('Click here', ['href' => controller/task/id', 'class' => 'nav'])
34
      */
35
    public static function a(string $href, string $label, array $attributes = [], $formatter = null): Element
36
    {
37
        $attributes['href'] = $href;
38
39
        return new Element('a', $label,$attributes, $formatter);
40
    }
41
}
42