Test Failed
Push — master ( e18acf...2713a2 )
by Marcio
12:48
created

FileLogger::write()   B

Complexity

Conditions 9
Paths 10

Size

Total Lines 26
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 26
rs 8.0555
c 1
b 0
f 0
cc 9
nc 10
nop 2
1
<?php
2
/**
3
 * KNUT7 K7F (https://marciozebedeu.com/)
4
 * KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @link      https://github.com/knut7/framework/ for the canonical source repository
11
 * @copyright (c) 2015.  KNUT7  Software Technologies AO Inc. (https://marciozebedeu.com/)
12
 * @license   https://marciozebedeu.com/license/new-bsd New BSD License
13
 * @author    Marcio Zebedeu - [email protected]
14
 * @version   1.0.7
15
 */
16
17
18
namespace Ballybran\Helpers\Log;
19
20
21
class FileLogger implements iLogger
22
{
23
24
25
    /**
26
     * @var
27
     */
28
    private $handle;
29
    /**
30
     * @var
31
     */
32
    private $filename;
33
    /**
34
     * @var
35
     */
36
    private $handles;
37
38
39
    public function __construct(string $filePath)
40
    {
41
        $this->filename = $filePath;
42
    }
43
44
45
    /**
46
     *
47
     * @param type $message
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...
48
     * @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...
49
     */
50
    public function write($message, string $type = null)
51
    {
52
        if ($this->handle = fopen(getcwd() . DS. DIR_STORAGE.$this->filename, 'a')) {
53
            if (is_array($message) && $type == 'A') {
0 ignored issues
show
introduced by
The condition is_array($message) is always false.
Loading history...
54
                foreach ($message as $key => $value) {
55
                    fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($key . " -> " . $value, true) . "\n");
56
57
                }
58
            }
59
//            if (!empty($message)) {
60
//                fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
61
62
//            }
63
            // to use for get data
64
65
            if (is_array($message) && $type == 'F') {
0 ignored issues
show
introduced by
The condition is_array($message) is always false.
Loading history...
66
                foreach ($message as $key => $value) {
67
                    fwrite($this->handle, date('Y-m-d G:i:s') . ';' . print_r($key . "=>" . $value, true) . "\n") . "<br>";
68
69
                }
70
            }
71
        }
72
73
        fclose($this->handle);
0 ignored issues
show
Bug introduced by
It seems like $this->handle can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

73
        fclose(/** @scrutinizer ignore-type */ $this->handle);
Loading history...
74
        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...
75
            chmod(getcwd() . DS. DIR_STORAGE.$this->filename, 0755);
76
        }
77
    }
78
79
    /**
80
     *
81
     */
82
    public function open()
83
    {
84
        if (file_exists($this->filename) && is_readable($this->filename) && $this->handles = fopen($this->filename, 'r')) {
85
            require_once VIEW . 'header.phtml';
86
            ?>
87
            <div class="well">
88
                <ul>
89
                    <?php
90
                    while (!feof($this->handles)) {
91
                        $content = fgets($this->handles);
92
93
                        if (trim($content) != "") {
94
                            echo "<li style='color: blue'>$content</li>";
95
                        }
96
                    } ?>
97
98
                </ul>
99
            </div>
100
            <?php
101
            fclose($this->handles);
102
103
        } else {
104
            echo "Could not read from {$this->filename}";
105
        }
106
    }
107
108
    /**
109
     *
110
     */
111
    public function __destruct()
112
    {
113
        $this->filename;
114
    }
115
116
    /**
117
     *
118
     * @param type $files
119
     * @return type
120
     */
121
    public function files($files)
122
    {
123
        return $this->filename = $files;
124
    }
125
126
127
}