Passed
Push — master ( 6b8ca8...3384db )
by Paul
04:57
created

PublicController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 55
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A filterEnqueuedScripts() 0 6 3
A filterQueryVars() 0 12 4
A postSubmitReview() 0 8 3
A enqueueAssets() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use GeminiLabs\SiteReviews\Abstracts\Controller;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GeminiLabs\SiteReviews\Controllers\Controller. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
The type GeminiLabs\SiteReviews\Abstracts\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use GeminiLabs\SiteReviews\Application;
7
use GeminiLabs\SiteReviews\Commands\SubmitReview;
8
use GeminiLabs\SiteReviews\Database\OptionManager;
9
use GeminiLabs\SiteReviews\Handlers\EnqueueAssets;
10
use GeminiLabs\SiteReviews\Modules\Validator\ValidateReview;
11
12
class PublicController extends Controller
13
{
14
	/**
15
	 * @return void
16
	 * @action wp_enqueue_scripts
17
	 */
18
	public function enqueueAssets()
19
	{
20
		(new EnqueueAssets)->handle();
0 ignored issues
show
Bug introduced by
The call to GeminiLabs\SiteReviews\H...EnqueueAssets::handle() has too few arguments starting with command. ( Ignorable by Annotation )

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

20
		(new EnqueueAssets)->/** @scrutinizer ignore-call */ handle();

This check compares calls to functions or methods with their respective definitions. If the call has less 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...
21
	}
22
23
	/**
24
	 * @return string
25
	 * @filter script_loader_tag
26
	 */
27
	public function filterEnqueuedScripts( $tag, $handle )
28
	{
29
		return $handle == Application::ID.'/google-recaptcha'
30
			&& glsr( OptionManager::class )->get( 'settings.reviews-form.recaptcha.integration' ) == 'custom'
31
			? str_replace( ' src=', ' async defer src=', $tag )
32
			: $tag;
33
	}
34
35
	/**
36
	 * Add a variable to query_vars for custom pagination
37
	 * @param array $vars
38
	 * @return array
39
	 * @filter query_vars
40
	 * @todo remove need for dirty hack
41
	 */
42
	public function filterQueryVars( $vars )
43
	{
44
		$vars[] = Application::PAGED_QUERY_VAR;
45
		// dirty hack to fix a form submission with a field that has "name" as name
46
		if( filter_input( INPUT_POST, 'action' ) == 'submit-review'
47
			&& !is_null( filter_input( INPUT_POST, 'gotcha' ))) {
48
			$index = array_search( 'name', $vars, true );
49
			if( false !== $index ) {
50
				unset( $vars[$index] );
51
			}
52
		}
53
		return $vars;
54
	}
55
56
	/**
57
	 * @return mixed
58
	 */
59
	public function postSubmitReview( array $request )
60
	{
61
		$validated = glsr( ValidateReview::class )->validate( $request );
62
		if( !empty( $validated->error )) {
63
			return $validated->request;
64
		}
65
		if( $validated->recaptchaIsUnset )return;
66
		return $this->execute( new SubmitReview( $validated->request ));
67
	}
68
}
69