Completed
Pull Request — master (#61)
by
unknown
37s
created

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
 *
4
 * VigLink extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\viglink;
12
13
/**
14
 * Extension class for custom enable/disable/purge actions
15
 */
16
class ext extends \phpbb\extension\base
17
{
18
	/**
19
	 * Check whether or not the extension can be enabled.
20
	 * The current phpBB version should meet or exceed
21
	 * the minimum version required by this extension:
22
	 *
23
	 * Requires phpBB 3.2.0-b1 or greater
24
	 *
25
	 * @return bool
0 ignored issues
show
Should the return type not be integer|boolean?

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...
26
	 */
27
	public function is_enableable()
28
	{
29
		return phpbb_version_compare(PHPBB_VERSION, '3.2.0-b1', '>=');
0 ignored issues
show
Bug Compatibility introduced by
The expression phpbb_version_compare(PH...ION, '3.2.0-b1', '>='); of type integer|boolean adds the type integer to the return on line 29 which is incompatible with the return type declared by the interface phpbb\extension\extension_interface::is_enableable of type boolean|array.
Loading history...
30
	}
31
32
	/**
33
	 * Check phpBB's VigLink switches and set them during install
34
	 *
35
	 * @param	mixed	$old_state	The return value of the previous call
36
	 *								of this method, or false on the first call
37
	 *
38
	 * @return	mixed				Returns false after last step, otherwise
39
	 *								temporary state which is passed as an
40
	 *								argument to the next step
41
	 */
42
	public function enable_step($old_state)
43
	{
44
		if ($old_state === false)
45
		{
46
			$viglink_helper = new \phpbb\viglink\acp\viglink_helper(
47
				$this->container->get('cache.driver'),
0 ignored issues
show
$this->container->get('cache.driver') is of type object|null, but the function expects a object<phpbb\cache\driver\driver_interface>.

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...
48
				$this->container->get('config'),
0 ignored issues
show
$this->container->get('config') is of type object|null, but the function expects a object<phpbb\config\config>.

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...
49
				$this->container->get('file_downloader'),
0 ignored issues
show
$this->container->get('file_downloader') is of type object|null, but the function expects a object<phpbb\file_downloader>.

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
				$this->container->get('language'),
0 ignored issues
show
$this->container->get('language') is of type object|null, but the function expects a object<phpbb\language\language>.

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...
51
				$this->container->get('log'),
0 ignored issues
show
$this->container->get('log') is of type object|null, but the function expects a object<phpbb\log\log>.

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...
52
				$this->container->get('user')
0 ignored issues
show
$this->container->get('user') is of type object|null, but the function expects a object<phpbb\user>.

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...
53
			);
54
55
			try
56
			{
57
				$viglink_helper->set_viglink_services();
58
			}
59
			catch (\RuntimeException $e)
60
			{
61
				$viglink_helper->log_viglink_error($e->getMessage());
62
			}
63
64
			return 'viglink';
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'viglink'; (string) is incompatible with the return type of the parent method phpbb\extension\base::enable_step of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
65
		}
66
67
		return parent::enable_step($old_state);
68
	}
69
}
70