Catalog   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A categoryCount() 0 4 1
A productCount() 0 4 1
A countEntity() 0 11 2
1
<?php
2
/**
3
 * Mage Scan
4
 *
5
 * PHP version 5
6
 *
7
 * @category  MageScan
8
 * @package   MageScan
9
 * @author    Steve Robbins <[email protected]>
10
 * @copyright 2015 Steve Robbins
11
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
12
 * @link      https://github.com/steverobbins/magescan
13
 */
14
15
namespace MageScan\Check;
16
17
/**
18
 * Scan for category and product information
19
 *
20
 * @category  MageScan
21
 * @package   MageScan
22
 * @author    Steve Robbins <[email protected]>
23
 * @copyright 2015 Steve Robbins
24
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
25
 * @link      https://github.com/steverobbins/magescan
26
 */
27
class Catalog extends AbstractCheck
28
{
29
    /**
30
     * Try to figure out how many categories there are in the store
31
     *
32
     * @return string|boolean
33
     */
34
    public function categoryCount()
35
    {
36
        return $this->countEntity('category');
37
    }
38
39
    /**
40
     * Try to figure out how many products there are in the store
41
     *
42
     * @return string|boolean
43
     */
44
    public function productCount()
45
    {
46
        return $this->countEntity('product');
47
    }
48
49
    /**
50
     * Count different entity types
51
     *
52
     * @param string $entity
53
     *
54
     * @return string|boolean
55
     */
56
    protected function countEntity($entity)
57
    {
58
        $request      = $this->getRequest();
59
        $response     = $request->get('catalog/seo_sitemap/' . $entity);
60
        $responseBody = $response->getBody()->getContents();
61
        $match        = $request->findMatchInResponse($responseBody, '/-?[0-9]+[a-z0-9- ]+ of ([0-9]+)/');
62
        if (!$match) {
63
            $match = $request->findMatchInResponse($responseBody, '/([0-9]+) Item\(s\)/');
64
        }
65
        return $match;
66
    }
67
}
68