TextParser::replaceUrls()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.4285
1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 09.10.2015 16:56
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Interfaces\Slack;
13
14
class TextParser extends \Interfaces\Gitter\TextParser
15
{
16
17
    /**
18
     * @brief Replaces BBCode urls.
19
     */
20
    protected function replaceUrls() {
21
22
        $this->text = preg_replace_callback('%\[url\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\]([\W\D\w\s]*?)\[/url\]%iu',
23
24
            function ($matches) {
25
                if (isset($matches[1]) && isset($matches[2]))
26
                    return "<".$matches[1]."|".$matches[2].">";
27
                else
28
                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
0 ignored issues
show
Bug introduced by
The property id 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...
29
            },
30
31
            $this->text
32
        );
33
34
    }
35
}