Completed
Push — master ( 8260e2...8ffaa6 )
by Nicklas
02:17
created

ActiveRecordModelExtender::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nicklas\Comment\Modules;
4
5
use \Anax\Database\ActiveRecordModel;
6
use \Nicklas\Comment;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Nicklas\Comment\Modules\Comment.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
8
use \Anax\TextFilter\TextFilter;
9
10
/**
11
 * A database driven model.
12
 */
13
class ActiveRecordModelExtender extends ActiveRecordModel
14
{
15
16
    public $db;
17
    /**
18
     * Constructor injects with database
19
     *
20
     */
21 17
     public function __construct($db = null)
22
     {
23 17
         $this->db = $db;
24 17
     }
25
    /**
26
     * Returns gravatar link
27
     *
28
     * @param string $email
29
     *
30
     * @return string as gravatar link
31
     */
32 7
    public function gravatar($email)
33
    {
34 7
        return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "&s=" . 40;
35
    }
36
37
    /**
38
     * Return markdown based on string
39
     *
40
     * @param string $content unparsed markdown
41
     *
42
     * @return string as parsed markdown
43
     */
44 3
    public function getMD($content)
45
    {
46 3
        $funcArr = ["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"];
47 3
        $textFilter = new textFilter();
48 3
        return $textFilter->parse($content, $funcArr)->text;
49
    }
50
}
51