Passed
Push — v5.x ( 00e299...57c2ac )
by Thierry
11:16
created

AlertLibrary::info()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * AlertLibrary.php
5
 *
6
 * Implements the dialog message and question features using the js alert and confirm functions.
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
14
15
namespace Jaxon\App\Dialog\Library;
16
17
use Jaxon\App\Dialog\LibraryInterface;
18
use Jaxon\App\Dialog\MessageInterface;
19
use Jaxon\App\Dialog\QuestionInterface;
20
21
class AlertLibrary implements LibraryInterface, MessageInterface, QuestionInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class AlertLibrary
Loading history...
22
{
23
    use DialogLibraryTrait;
24
    use MessageTrait;
25
26
    /**
27
     * Get the library name
28
     *
29
     * @return string
30
     */
31
    public function getName(): string
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
32
    {
33
        return ''; // No name
34
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
35
36
    /**
37
     * Get the script which makes a call only if the user answers yes to the given question
38
     *
39
     * @param string  $sQuestion
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
40
     * @param string  $sYesScript
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
41
     * @param string  $sNoScript
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
42
     *
43
     * @return string
44
     */
45
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
46
    {
47
        return empty($sNoScript) ? 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}' :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
Bug Best Practice introduced by
The expression return empty($sNoScript)...e{' . $sNoScript . ';}' returns the type string which is incompatible with the return type mandated by Jaxon\App\Dialog\QuestionInterface::confirm() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
48
            'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}else{' . $sNoScript . ';}';
49
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $sMessage should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $sTitle should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $sType should have a doc-comment as per coding-style.
Loading history...
52
     * @inheritDoc
53
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
54
    protected function alert(string $sMessage, string $sTitle, string $sType)
0 ignored issues
show
Unused Code introduced by
The parameter $sType 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

54
    protected function alert(string $sMessage, string $sTitle, /** @scrutinizer ignore-unused */ string $sType)

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...
55
    {
56
        if(!empty($sTitle))
57
        {
58
            $sMessage = '<b>' . $sTitle . '</b><br/>' . $sMessage;
59
        }
60
        $this->xResponse->alert($sMessage, $sTitle);
0 ignored issues
show
Unused Code introduced by
The call to Jaxon\Response\Response::alert() has too many arguments starting with $sTitle. ( Ignorable by Annotation )

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

60
        $this->xResponse->/** @scrutinizer ignore-call */ 
61
                          alert($sMessage, $sTitle);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
61
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
62
}
63