Test Failed
Push — master ( 7bbbf4...34ff55 )
by Julien
04:57
created

Clamav::statsAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Controller;
13
14
use Xenolope\Quahog\Client;
15
use Zemit\Mvc\View;
16
17
/**
18
 * @property View $view
19
 * @property Client $clamav
20
 */
21
trait Clamav
22
{
23
    public function indexAction(): void
24
    {
25
        $this->clamav->startSession();
26
        $this->pingAction();
27
        $this->versionAction();
28
        $this->statsAction();
29
        $this->clamav->endSession();
30
    }
31
    
32
    public function scanAction(?string $filePath = null): bool
33
    {
34
        $this->clamav->startSession();
35
        $result = $this->clamav->scanFile($filePath);
36
        $this->clamav->endSession();
37
        
38
        $ret = [];
39
        $ret['ok'] = $result->isOk();
40
        $ret['error'] = $result->isError();
41
        $ret['found'] = $result->isFound();
42
        $ret['reason'] = $result->getReason();
43
        $ret['id'] = $result->getId();
44
        $ret['filename'] = $result->getFilename();
45
        
46
        $this->view->setVars($ret);
47
        
48
        return $ret['ok'];
49
    }
50
    
51
    public function pingAction(): bool
52
    {
53
        $ret = $this->clamav->ping();
54
        $this->view->setVar('ping', $ret);
55
        return $ret;
56
    }
57
    
58
    public function versionAction(): bool
59
    {
60
        $ret = $this->clamav->version();
61
        $this->view->setVar('version', $ret);
62
        return !empty($ret);
63
    }
64
    
65
    public function statsAction(): bool
66
    {
67
        $ret = $this->clamav->stats();
68
        $this->view->setVar('stats', $ret);
69
        return !empty($ret);
70
    }
71
    
72
    public function reloadAction(): bool
73
    {
74
        $ret = $this->clamav->reload();
75
        $this->view->setVar('reload', $ret);
76
        return $ret === 'RELOADING';
77
    }
78
}
79