Completed
Push — master ( 25d3bb...a9232e )
by smiley
04:11
created

LanguageAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 1
A string() 0 8 2
1
<?php
2
/**
3
 * Class LanguageAbstract
4
 *
5
 * @filesource   LanguageAbstract.php
6
 * @created      11.02.2016
7
 * @package      chillerlan\BBCode\Language
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2015 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\bbcode\Language;
14
15
use chillerlan\bbcode\Traits\ClassLoaderTrait;
16
17
/**
18
 * @method string parserExceptionCallback($override_language = null)
19
 * @method string parserExceptionMatchall($override_language = null)
20
 *
21
 * @method string codeDisplayCSS($override_language = null)
22
 * @method string codeDisplayPHP($override_language = null)
23
 * @method string codeDisplaySQL($override_language = null)
24
 * @method string codeDisplayXML($override_language = null)
25
 * @method string codeDisplayHTML($override_language = null)
26
 * @method string codeDisplayJS($override_language = null)
27
 * @method string codeDisplayJSON($override_language = null)
28
 * @method string codeDisplayPRE($override_language = null)
29
 * @method string codeDisplayCODE($override_language = null)
30
 * @method string codeDisplayNSIS($override_language = null)
31
 *
32
 * @method string expanderDisplayExpander($override_language = null)
33
 * @method string expanderDisplayQuote($override_language = null)
34
 * @method string expanderDisplaySpoiler($override_language = null)
35
 * @method string expanderDisplayTrigger($override_language = null)
36
 */
37
abstract class LanguageAbstract implements LanguageInterface{
38
	use ClassLoaderTrait;
39
40
	/**
41
	 * It's magic.
42
	 *
43
	 * @param string $name
44
	 * @param array  $arguments
45
	 *
46
	 * @return mixed
47
	 */
48
	public function __call(string $name, array $arguments){
49
		return $this->string($name, ...$arguments);
0 ignored issues
show
Documentation introduced by
$arguments is of type array, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
	}
51
52
	/**
53
	 * Returns a language string for a given key and overrides the current language if desired.
54
	 *
55
	 * @param string $key
56
	 * @param string $override_language (a LanguageInterface FQCN)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $override_language not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
57
	 *
58
	 * @return mixed
59
	 * @throws \chillerlan\bbcode\BBCodeException
60
	 */
61
	public function string(string $key, string $override_language = null){
62
63
		if($override_language){
0 ignored issues
show
Bug Best Practice introduced by
The expression $override_language of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
64
			return $this->__loadClass($override_language, LanguageInterface::class)->{$key}();
65
		}
66
67
		return $this->{$key};
68
	}
69
70
}
71