Test Failed
Push — develop ( 289f4b...2384b4 )
by Paul
09:15 queued 10s
created

RestController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 21
c 1
b 0
f 0
dl 0
loc 63
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filterProductModel() 0 11 2
A filterRestApiSummaryArgs() 0 10 3
A filterProductsRequest() 0 19 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\SureCart\Controllers;
4
5
use GeminiLabs\SiteReviews\Contracts\ControllerContract;
6
use GeminiLabs\SiteReviews\HookProxy;
7
use SureCart\Models\Model;
0 ignored issues
show
Bug introduced by
The type SureCart\Models\Model 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...
8
9
class RestController implements ControllerContract
10
{
11
    use HookProxy;
12
13
    /**
14
     * @filter surecart/request/model
15
     */
16
    public function filterProductModel(Model $model, \WP_REST_Request $request): Model
0 ignored issues
show
Unused Code introduced by
The parameter $request 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

16
    public function filterProductModel(Model $model, /** @scrutinizer ignore-unused */ \WP_REST_Request $request): Model

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...
17
    {
18
        if (!is_a($model, 'SureCart\Models\Product')) {
19
            return $model;
20
        }
21
22
        // glsr_log($model);
23
        // glsr_log($request->get_param('id'));
24
        // $modelId = $request['id'] ?? '';
25
26
        return $model;
27
    }
28
29
30
    /**
31
     * @param WP_REST_Request|null $request The WP_REST_Request object
32
     * @param string|null          $method  The method of the request
33
     *
34
     * @return WP_REST_Request|null
35
     *
36
     * @filter rest_products_request
37
     */
38
    public function filterProductsRequest($request = null, $method = null)
0 ignored issues
show
Unused Code introduced by
The parameter $method 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

38
    public function filterProductsRequest($request = null, /** @scrutinizer ignore-unused */ $method = null)

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...
39
    {
40
        // if (!$request instanceof WP_REST_Request || 'find' !== $method) { // methods can be create, edit, delete & find.
41
        if (!$request instanceof WP_REST_Request) {
0 ignored issues
show
Bug introduced by
The type GeminiLabs\SiteReviews\I...rollers\WP_REST_Request was not found. Did you mean WP_REST_Request? If so, make sure to prefix the type with \.
Loading history...
42
            return $request;
43
        }
44
        // Add your custom logic here.
45
        // For example, you can modify the metadata param in the checkout request.
46
        $request_metadata = $request->get_param('metadata');
47
        $metadata = (object) array_merge(
48
            $request_metadata,
49
            [
50
                'key1' => 'value1',
51
                'key2' => 'value2',
52
                'key3' => 'value3',
53
            ]
54
        );
55
        $request->set_param('metadata', $metadata);
56
        return $request;
57
    }
58
59
    /**
60
     * @filter site-reviews/rest-api/summary/args
61
     */
62
    public function filterRestApiSummaryArgs(array $args, \WP_REST_Request $request): array
63
    {
64
        if ('/site-reviews/v1/summary/stars' !== $request->get_route()) {
65
            return $args;
66
        }
67
        if (!str_contains((string) $request->get_param('_block'), 'surecart-product-rating')) {
68
            return $args;
69
        }
70
        $args['theme'] = glsr_get_option('integrations.surecart.style');
71
        return $args;
72
    }
73
}
74