WpBridge   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 27
wmc 2
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 4 1
A camelToUnderscore() 0 4 1
1
<?php
2
namespace Gwa\Wordpress\WpBridge;
3
4
use Gwa\Wordpress\WpBridge\Contracts\WpBridgeInterface;
5
6
/**
7
 * Allows us to use a class to call methods in the global namespace.
8
 * Methods should be called in camelcase.
9
 *
10
 * To call
11
 * wp_get_attachment_image_src(...);
12
 * use
13
 * $bridge->wpGetAttachmentImageSrc(...);
14
 */
15
class WpBridge implements WpBridgeInterface
16
{
17
    /**
18
     * Magic call on all camel wordpress functions.
19
     *
20
     * @param string $function
21
     * @param array  $args
22
     *
23
     * @return mixed
24
     */
25
    public function __call($function, $args)
26
    {
27
        return call_user_func_array($this->camelToUnderscore($function), $args);
28
    }
29
30
    /**
31
     * Rename camelcase to underscore.
32
     *
33
     * @param string $string
34
     *
35
     * @return string
36
     */
37
    public function camelToUnderscore($string)
38
    {
39
        return strtolower(preg_replace('/([a-z])([A-Z0-9])/', '$1_$2', $string));
40
    }
41
}
42