GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 12d99c...2461fc )
by Adam
03:13
created

src/BaseControl.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace GulpAssets;
4
5
/**
6
 * @author Adam Bisek <[email protected]>
7
 */
8
class BaseControl extends \Nette\Application\UI\Control
9
{
10
11
	/** @var array */
12
	protected $files;
13
14
	/** @var string */
15
	private $basePath;
16
17
18
	/**
19
	 * @return array
20
	 */
21 4
	public function getFiles()
22
	{
23 4
		return $this->files;
24
	}
25
26
27
	/**
28
	 * @param array $files
29
	 */
30 6
	public function setFiles($files)
31
	{
32 6
		$this->files = $files;
33 6
	}
34
35
36
	/**
37
	 * @return string
38
	 */
39 2
	public function getBasePath()
40
	{
41 2
		return $this->basePath;
42
	}
43
44
45
	/**
46
	 * @param string $basePath
47
	 */
48 6
	public function setBasePath($basePath)
49
	{
50 6
		$this->basePath = $basePath;
51 6
	}
52
53
54 2
	protected function formatFileUrl($file)
55
	{
56 2
		$appendix = '';
57 2
		if(is_file($this->basePath . '/' . $file)){
58 2
			$appendix = '?' . md5(filemtime($this->basePath . '/' . $file));
59 2
		}
60
61 2
		return $this->template->baseUrl . '/' . $file . $appendix;
2 ignored issues
show
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Accessing baseUrl on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
62
	}
63
64
}