Test Failed
Push — master ( 48da91...4d2acf )
by Nicklas
01:59
created

ActiveRecordModelExtender::getMD()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
/**
9
 * A database driven model.
10
 */
11
class ActiveRecordModelExtender extends ActiveRecordModel
12
{
13
    /**
14
     * Returns gravatar link
15
     *
16
     * @param string $email
17
     *
18
     * @return string as gravatar link
19
     */
20
    public function gravatar($email)
21
    {
22
        return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "&s=" . 40;
23
    }
24
25
    /**
26
     * Return markdown based on string
27
     *
28
     * @param string $content unparsed markdown
29
     *
30
     * @return string as parsed markdown
31
     */
32
    public function getMD($content)
33
    {
34
        $funcArr = ["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"];
35
        return $this->di->get('textfilter')->parse($content, $funcArr)->text;
0 ignored issues
show
Bug introduced by
The property di does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
    }
37
}
38