Issues (1369)

classes/BBCodeParser.php (2 issues)

Severity
1
<?php
2
3
/**
4
 * Created by Gorlum 14.02.2017 11:18
5
 */
6
class BBCodeParser {
7
8
  /**
9
   * @var Design $design
10
   */
11
  protected $design;
12
13
  public function __construct(Core\GlobalContainer $gc) {
14
    $this->design = $gc->design;
15
  }
16
17
  protected function applyElements($elements, $text, $authorAccessLevel = AUTH_LEVEL_REGISTERED) {
18
    foreach ($elements as $auth_level => $element) {
19
      if ($auth_level > $authorAccessLevel) {
20
        continue;
21
      }
22
23
      foreach ($element as $find => $replace) {
24
        $text = preg_replace($find, $replace, $text);
25
      }
26
    }
27
28
    return $text;
29
  }
30
31
  /**
32
   * Expands bbCodes and smiles in text
33
   *
34
   * @param      $text
35
   * @param int  $authorAccessLevel
36
   * @param int  $encodeOptions - HTML_ENCODE_xxx constants. HTML_ENCODE_MULTILINE by default
37
   *
38
   * @return mixed
39
   */
40
  public function expandBbCode($text, $authorAccessLevel = AUTH_LEVEL_REGISTERED, $encodeOptions = HTML_ENCODE_MULTILINE) {
41
    $text = HelperString::htmlEncode($text, $encodeOptions);
42
43
    $text = $this->applyElements($this->design->getBbCodes(), $text, $authorAccessLevel);
44
    $text = $this->applyElements($this->design->getSmiles(), $text, $authorAccessLevel);
45
46
    return $text;
47
  }
48
49
  public function compactBbCode($text, $authorAccessLevel = AUTH_LEVEL_REGISTERED, $encodeOptions = HTML_ENCODE_MULTILINE) {
0 ignored issues
show
The parameter $authorAccessLevel is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
  public function compactBbCode($text, /** @scrutinizer ignore-unused */ $authorAccessLevel = AUTH_LEVEL_REGISTERED, $encodeOptions = HTML_ENCODE_MULTILINE) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $encodeOptions is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
  public function compactBbCode($text, $authorAccessLevel = AUTH_LEVEL_REGISTERED, /** @scrutinizer ignore-unused */ $encodeOptions = HTML_ENCODE_MULTILINE) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    // Replacing news://xxx link with BBCode
51
    $text = preg_replace("#news\:\/\/(\d+)#", "[news=$1]", $text);
52
    // Replacing news URL with BBCode
53
    $text = preg_replace("#(?:https?\:\/\/(?:.+)?\/announce\.php\?id\=(\d+))#", "[news=$1]", $text);
54
    $text = preg_replace("#(?:https?\:\/\/(?:.+)?\/index\.php\?page\=battle_report\&cypher\=([0-9a-zA-Z]{32}))#", "[ube=$1]", $text);
55
56
    return $text;
57
  }
58
}
59