Completed
Push — master ( d6ea78...1300b3 )
by Daniel
04:27
created

Html5Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 0
cbo 2
dl 0
loc 64
ccs 30
cts 30
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A wrapImgInFigure() 0 22 2
A doInit() 0 10 1
A getFilterMap() 0 12 1
1
<?php
2
namespace Gwa\Wordpress\Zero\Module;
3
4
use Gwa\Wordpress\WpBridge\Traits\WpBridgeTrait;
5
use Gwa\Wordpress\Zero\Module\AbstractThemeModule;
6
7
class Html5Module extends AbstractThemeModule
8
{
9
    use WpBridgeTrait;
10
11
    /**
12
     * Wrap images with figure tag.
13
     * Courtesy of Interconnectit http://interconnectit.com/2175/how-to-remove-p-tags-from-images-in-wordpress/
14
     *
15
     * @param string $content
16
     *
17
     * @return string
18
     */
19
    public function wrapImgInFigure($content)
20
    {
21 1
        $callback = function ($matches) {
22 1
            $img     = $matches[1];
23 1
            $pattern = '/class="([^"]+)"/';
24
25 1
            preg_match($pattern, $img, $matches);
26
27 1
            $classes = $matches[1];
28 1
            $class   = '';
29
30 1
            if (isset($classes)) {
31 1
                $class = ' class="' . $classes . '"';
32 1
            }
33
34 1
            return '<figure' . $class . '>' . $img . '</figure>';
35 1
        };
36
37 1
        $content = preg_replace_callback('/(<a .*?><img.*?><\/a>|<img.*?>)/s', $callback, $content);
38
39 1
        return $content;
40
    }
41
42 1
    protected function doInit()
43
    {
44 1
        $this->getWpBridge()->addThemeSupport('html5', [
45 1
            'search-form',
46 1
            'comment-form',
47 1
            'comment-list',
48 1
            'gallery',
49 1
            'caption',
50 1
        ]);
51 1
    }
52
53
    /**
54
     * Override in concrete subclass.
55
     *
56
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string|Html5Module|integer>[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
57
     */
58 1
    protected function getFilterMap()
59
    {
60
        return [
61
            [
62 1
                'hooks'  => 'the_content',
63 1
                'class'  => $this,
64 1
                'method' => 'wrapImgInFigure',
65 1
                'prio'   => 30,
66 1
                'args'   => 1,
67 1
            ],
68 1
        ];
69
    }
70
}
71