Passed
Push — develop ( 7c77c8...ea4b85 )
by Andrew
05:55
created

SeoProduct::sitemapElementsQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS 3.x
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2017 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\seoelements;
13
14
use nystudio107\seomatic\base\SeoElementInterface;
15
use nystudio107\seomatic\models\MetaBundle;
16
17
use craft\base\ElementInterface;
18
use craft\elements\db\ElementQueryInterface;
19
20
use craft\commerce\elements\Product;
0 ignored issues
show
Bug introduced by
The type craft\commerce\elements\Product 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...
21
22
/**
23
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
24
 * @package   Seomatic
25
 * @since     3.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
26
 */
0 ignored issues
show
Coding Style introduced by
Missing @license tag in class comment
Loading history...
27
class SeoProduct implements SeoElementInterface
28
{
29
    // Constants
30
    // =========================================================================
31
32
    const META_BUNDLE_TYPE = 'product';
33
    const REQUIRED_PLUGIN_HANDLE = 'commerce';
34
35
    // Static Methods
36
    // =========================================================================
37
38
    /**
39
     * Return the sourceBundleType for that this SeoElement handles
40
     *
41
     * @return string
42
     */
43
    public static function getMetaBundleType(): string
44
    {
45
        return self::META_BUNDLE_TYPE;
46
    }
47
48
    /**
49
     * Return the handle to a required plugin for this SeoElement type
50
     *
51
     * @return null|string
52
     */
53
    public static function getRequiredPluginHandle()
54
    {
55
        return self::REQUIRED_PLUGIN_HANDLE;
56
    }
57
58
    /**
59
     * Return an ElementQuery for the sitemap elements for the given MetaBundle
60
     *
61
     * @param MetaBundle $metaBundle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
62
     *
63
     * @return ElementQueryInterface
64
     */
65
    public static function sitemapElementsQuery(MetaBundle $metaBundle): ElementQueryInterface
66
    {
67
        $query = Product::find()
68
            ->type($metaBundle->sourceHandle)
69
            ->siteId($metaBundle->sourceSiteId)
70
            ->limit($metaBundle->metaSitemapVars->sitemapLimit)
71
            ->enabledForSite(true);
72
73
        return $query;
74
    }
75
76
    /**
77
     * Return an ElementInterface for the sitemap alt element for the given MetaBundle
78
     * and Element ID
79
     *
80
     * @param MetaBundle $metaBundle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
81
     * @param int        $elementId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
82
     * @param int        $siteId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
83
     *
84
     * @return null|ElementInterface
85
     */
86
    public static function sitemapAltElement(
87
        MetaBundle $metaBundle,
88
        int $elementId,
89
        int $siteId
90
    ): ElementInterface {
91
        return Product::find()
92
            ->id($elementId)
93
            ->siteId($siteId)
94
            ->limit(1)
95
            ->enabledForSite(true)
96
            ->one();
97
    }
98
}
99