SubdomainHtmlHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 22
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B link() 0 11 6
1
<?php
2
/**
3
 * CakePHP Plugin : CakePHP Subdomain Routing
4
 * Copyright (c) Multidimension.al (http://multidimension.al)
5
 * Github : https://github.com/multidimension-al/cakephp-subdomains
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE file
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright (c) Multidimension.al (http://multidimension.al)
12
 * @link      https://github.com/multidimension-al/cakephp-subdomains Github
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
namespace Multidimensional\Subdomains\View\Helper;
17
18
use Cake\View\Helper\HtmlHelper;
19
20
class SubdomainHtmlHelper extends HtmlHelper
21
{
22
23
    /**
24
     * @param string            $title   The content to be wrapped by `<a>` tags.
25
     * @param string|array|null $url     Cake-relative URL or array of URL parameters, or external URL (starts with http://)
26
     *   external URL (starts with http://)
27
     * @param array             $options Array of options and HTML attributes.
28
     * @return string An `<a />` element.
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
29
     */
30
    public function link($title, $url = null, array $options = [])
31
    {
32
        if (isset($url['prefix']) && $url['prefix'] === false) {
33
            $url['prefix'] = "false";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal false does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
34
        }
35
        if (is_array($title) && isset($title['prefix']) && $title['prefix'] === false) {
36
            $title['prefix'] = "false";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal false does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
37
        }
38
39
        return parent::link($title, $url, $options);
0 ignored issues
show
Bug introduced by
It seems like $title can also be of type array<string,?,{"prefix":"?"}>; however, Cake\View\Helper\HtmlHelper::link() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
40
    }
41
}
42