Log   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 20
eloc 40
dl 0
loc 112
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A open() 0 23 6
A Files() 0 3 1
A __construct() 0 10 2
A __destruct() 0 3 1
B write() 0 25 10
1
<?php
2
3
/**
4
 * KNUT7 K7F (https://marciozebedeu.com/)
5
 * KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/)
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @link      https://github.com/knut7/framework/ for the canonical source repository
12
 * @copyright (c) 2015.  KNUT7  Software Technologies AO Inc. (https://marciozebedeu.com/)
13
 * @license   https://marciozebedeu.com/license/new-bsd New BSD License
14
 * @author    Marcio Zebedeu - [email protected]
15
 * @version   1.0.2
16
 */
17
18
namespace Ballybran\Helpers\Log;
19
20
21
/**
22
 * Class Log
23
 * @package Ballybran\Helpers\Log
24
 */
25
class Log
26
{
27
28
    /**
29
     * @var
30
     */
31
    private $handle;
32
    /**
33
     * @var
34
     */
35
    private $filename;
36
    /**
37
     * @var
38
     */
39
    private $handles;
40
41
    /**
42
     *
43
     * @param type $filename
0 ignored issues
show
Bug introduced by
The type Ballybran\Helpers\Log\type 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...
44
     * @param null $dir
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dir is correct as it would always require null to be passed?
Loading history...
45
     */
46
    public function __construct($filename, $dir = null)
47
    {
48
49
        if ($dir != null) {
0 ignored issues
show
introduced by
The condition $dir != null is always false.
Loading history...
50
51
            $this->filename = $dir . $filename;
52
53
        } else {
54
55
            $this->filename = DIR_LOGS . $filename;
56
        }
57
    }
58
59
    /**
60
     *
61
     * @param type $message
62
     * @param null $type
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $type is correct as it would always require null to be passed?
Loading history...
63
     */
64
    public function write($message, $type = null)
65
    {
66
        if ($this->handle = fopen($this->filename, 'a')) {
67
            if (is_array($message) && $type === 'A') {
0 ignored issues
show
introduced by
The condition is_array($message) is always false.
Loading history...
68
                foreach ($message as $key => $value) {
69
                    fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($key . " -> " . $value, true) . "\n");
70
71
                }
72
            }
73
            if (!empty($message)) {
74
                fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
0 ignored issues
show
Bug introduced by
Are you sure print_r($message, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
                fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . /** @scrutinizer ignore-type */ print_r($message, true) . "\n");
Loading history...
75
76
            }
77
            // to use for get data
78
79
            if (is_array($message) && $type == 'F') {
0 ignored issues
show
introduced by
The condition is_array($message) is always false.
Loading history...
80
                foreach ($message as $key => $value) {
81
                    fwrite($this->handle, date('Y-m-d G:i:s') . ';' . print_r($key . "=>" . $value, true) . "\n") . "<br>";
82
83
                }
84
            }
85
        }
86
        fclose($this->handle);
87
        if ($this->filename == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->filename of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
88
            chmod($this->filename, 0755);
89
        }
90
    }
91
92
    /**
93
     *
94
     */
95
    public function open()
96
    {
97
        if (file_exists($this->filename) && is_readable($this->filename) && $this->handles = fopen($this->filename, 'r')) {
98
            require_once DIR_FILE . 'View/header.phtml';
99
            ?>
100
            <div class="well">
101
                <ul>
102
                    <?php
103
                    while (!feof($this->handles)) {
104
                        $content = fgets($this->handles);
105
106
                        if (trim($content) != "") {
107
                            echo "<li style='color: blue'>$content</li>";
108
                        }
109
                    } ?>
110
111
                </ul>
112
            </div>
113
            <?php
114
            fclose($this->handles);
115
116
        } else {
117
            echo "Could not read from {$this->filename}";
118
        }
119
    }
120
121
    /**
122
     *
123
     */
124
    public function __destruct()
125
    {
126
        $this->filename;
127
    }
128
129
    /**
130
     *
131
     * @param type $files
132
     * @return type
133
     */
134
    public function Files($files)
135
    {
136
        return $this->files = $files;
0 ignored issues
show
Bug Best Practice introduced by
The property files does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
137
    }
138
139
}
140