stats::log()   B
last analyzed

Complexity

Conditions 11
Paths 8

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
nc 8
nop 0
dl 0
loc 43
rs 7.3166
c 0
b 0
f 0
ccs 0
cts 26
cp 0
crap 132

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
4
    /******************************************************************
5
     mod_stats.php                                         Muze Ariadne
6
     ------------------------------------------------------------------
7
     Author: Florian Overkamp ([email protected])
8
     Date: 4 february 2003
9
10
     Copyright 2003 ObSimRef and Muze
11
12
     This file is part of Ariadne.
13
14
     Ariadne is free software; you can redistribute it and/or modify
15
     it under the terms of the GNU General Public License as published
16
     by the Free Software Foundation; either version 2 of the License,
17
     or (at your option) any later version.
18
19
     Ariadne is distributed in the hope that it will be useful,
20
     but WITHOUT ANY WARRANTY; without even the implied warranty of
21
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
     GNU General Public License for more details.
23
24
     You should have received a copy of the GNU General Public License
25
     along with Ariadne; if not, write to the Free Software
26
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27
     02111-1307  USA
28
29
    -------------------------------------------------------------------
30
31
     Description:
32
33
	   This module calls the stats tools with the given
34
	   options.
35
36
    ******************************************************************/
37
38
 	$StatsSupportedTools = "phpOpenTracker";
39
40
	class stats {
41
42
43
		function log() {
0 ignored issues
show
Coding Style introduced
log uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
44
			// all info is gathered from the php/webserver environment
45
			global $AR, $StatsSupportedTools;
46
			global $path;
47
48
			if($AR->Stats->makestats && (stristr($StatsSupportedTools, $AR->Stats->tool)!=false)) {
0 ignored issues
show
Bug Best Practice introduced
It seems like you are loosely comparing stristr($StatsSupportedTools, $AR->Stats->tool) of type string to the boolean false. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
49
				// Go Go Go
50
				$client_id = $_SERVER[$AR->Stats->clientvar];
51
				$referer =  $_SERVER['HTTP_REFERER'];
52
53
				//$cookie=ldGetCredentials();
54
				//$username = $cookie[$ARCurrent->session->id]['login'];
55
56
				// log the entry if there is a CLIENT_ID
57
				if((isset($client_id)) || (!$AR->Stats->logdefault)) {
58
					// Take logdefault if there is no CLIENT_ID
59
60
					// Mangle the path (adjust to your own taste)
61
					$logpath = $path;
62
					$proceed = true;
63
64
					// Small tests for stuff we never want to log (i.e. access to /system/)
65
					// set $proceed to false if you wish to skip this log
66
					if(is_array($AR->Stats->ignore)) {
67
						foreach($AR->Stats->ignore as $ignorepath) {
68
							if(substr($logpath, 0, strlen($ignorepath)) == $ignorepath) $proceed = false;
69
							// path may contain NLS data
70
							if(substr($logpath, 3, strlen($ignorepath)) == $ignorepath) $proceed = false;
71
						}
72
					}
73
74
					if($proceed) {
75
						// Do the logging
76
						debug ("mod_stats::log: path = $logpath", "class");
77
						switch($AR->Stats->tool) {
78
       	                        			case "phpOpenTracker":	$this->opentrackerlog($logpath, $referer, $client_id);
79
						}
80
					} else {
81
						debug ("mod_stats::log: path NOT logged ($logpath)", "class");
82
					}
83
				}
84
			}
85
		}
86
87
//
88
// All function below are tool-specific
89
//
90
91
		function opentrackerlog($logpath, $referer, $client_id) {
92
			// opentracker specific
93
			global $AR;
94
95
			// phpOpenTracker User Tracking
96
			require_once($AR->Stats->path);
97
			debug ("mod_stats::opentrackerlog: logging $logpath to phpOpenTracker", "class");
98
			// log the visitor
99
			if($client_id != "") {
100
				debug ("mod_stats::opentrackerlog: client_id = $client_id", "class");
101
				@phpOpenTracker::log( Array(
102
					'document' => $logpath,
103
					'referer' => $referer,
104
					'client_id' => $client_id)
105
				);
106
			} else {
107
				debug ("mod_stats::opentrackerlog: logging without client_id", "class");
108
				@phpOpenTracker::log( Array(
109
					'document' => $logpath,
110
					'referer' => $referer)
111
				);
112
			}
113
			// ---
114
		}
115
116
		// Class end
117
	}
118