Passed
Push — master ( 64bf92...7a79e7 )
by Ruben
02:16 queued 10s
created

SiteAnalyzer::getTransitionMatrix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * (c) Ruben Dorado <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
namespace SiteAnalyzer;
10
11
use Exception;
12
13
/**
14
 * class SiteAnalyzer
15
 *
16
 * @package   SiteAnalyzer
17
 * @author    Ruben Dorado <[email protected]>
18
 * @copyright 2018 Ruben Dorado
19
 * @license   http://www.opensource.org/licenses/MIT The MIT License
20
 */
21
class SiteAnalyzer
22
{
23
24
    
25
    /*
26
     * @param 
27
     */
28
    public static function count($options = [])
29
    {	
30
        $config = SiteAnalyzer::loadConfig(array_key_exists('pdo', $options));
31
        
32
        if (array_key_exists('pdo', $options)) {            
33
            $pdo = $options['pdo'];	
34
        } else {            
35
            $pdo = Persistence::getPDO($config);
36
        }
37
        
38
        try {
39
            return Persistence::updateCount($pdo, $config, $options);
40
        } catch (Exception $e) {
41
            try {
42
                Persistence::crateDatabase($pdo, $config);
43
                return Persistence::updateCount($pdo, $config, $options);
44
            } catch (Exception $e) {
45
                throw new Exception("Site Analyzer could connect to the database.".$e->getMessage());
46
            };
47
            
48
        };
49
            
50
    }
51
52
    
53
    /*
54
     * @param $format string, one of [php-array, xml, json, txt-csv]
55
     */
56
    public static function loadConfig($pdoProvided = FALSE)
57
    {
58
        try {
59
            $config = new Configuration("../../../../site-analyzer.ini", $pdoProvided);
60
        } catch (Exception $e) {
61
            try {
62
                $config = new Configuration("site-analyzer.ini", $pdoProvided); 
63
            } catch (Exception $e) {
64
                throw new Exception("Config file not found.");
65
            }
66
        }        
67
        return $config;
68
    }
69
70
    /*
71
     * @param $format string, one of [php-array, xml, json, txt-csv]
72
     */
73
    public static function getStats($pdo = null)
74
    {   
75
        $config = SiteAnalyzer::loadConfig();
76
        //*$config = new Configuration("site-analyzer.ini", isset($pdo));
77
        if ($pdo==null) {
78
            $pdo = Persistence::getPDO($config);
79
        }
80
        
81
        $data = Persistence::getCounts($pdo, $config);
82
        return $data;
83
    } 
84
85
    
86
    /*
87
     * @param
88
     */
89
    public static function groupHitsByTime($options, $pdo = null)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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

89
    public static function groupHitsByTime(/** @scrutinizer ignore-unused */ $options, $pdo = 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...
90
    {
91
        $config = SiteAnalyzer::loadConfig();
92
        if ($pdo==null) {
93
            $pdo = Persistence::getPDO($config);
94
        }
95
        $data = OptionsDAO::getHitsWithOptions($pdo, $config);
96
        $resp = [];
97
        foreach ($data as $row) {
98
            $tmp = [$row['id']];
99
            $tmp = array_merge($tmp, getdate($row['time']));
100
            $resp[] = $tmp;
101
        }        
102
        return $resp;        
103
    }
104
    
105
106
    /*
107
     * @param
108
     */
109
    public static function groupHitsByUser($pdo = null)
110
    {
111
        $config = new Configuration("site-analyzer.ini", isset($pdo));
112
        if ($pdo==null) {
113
            $pdo = Persistence::getPDO($config);
114
        }
115
        $data = OptionsDAO::getHitsWithOptions($pdo, $config);        
116
        $count = [];
117
        foreach ($data as $row) {
118
            if (array_key_exists($row['user'], $count)) {
119
                $count[$row['user']]++;
120
            } else {
121
                $count[$row['user']] = 1;
122
            }            
123
        }
124
        
125
        $resp = [];
126
        foreach ($count as $user => $count) {
127
            $resp[] = [$user, $count];
128
        }
129
        return $resp;        
130
    }
131
    
132
    /*
133
     * @param $format string, one of [php-array, xml, json, txt-csv]
134
     */
135
    public static function transform($data, $format)
136
    {
137
        if ($format=="html") {
138
            $resp = "<table style='border-collapse: collapse;border: 1px solid black;'>";
139
            foreach ($data as $row) {
140
                $resp .= "<tr style='border: 1px solid black;'>";
141
                foreach ($row as $cell) {
142
                    $resp .= "<td style='border: 1px solid black;'>$cell</td>";
143
                }  
144
                $resp .= "</tr>";
145
            }
146
            return $resp."</table>";
147
        }
148
        return $data; 
149
    } 
150
151
152
    /*
153
     * @param
154
     */
155
    public static function getTransitionMatrix()
156
    {
157
158
    } 
159
 
160
161
    /*
162
     * @param
163
     */
164
    public static function performABTest($tests, $targets)
0 ignored issues
show
Unused Code introduced by
The parameter $targets 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

164
    public static function performABTest($tests, /** @scrutinizer ignore-unused */ $targets)

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...
Unused Code introduced by
The parameter $tests 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

164
    public static function performABTest(/** @scrutinizer ignore-unused */ $tests, $targets)

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...
165
    {
166
167
    } 
168
169
}
170
171