UtilFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 59
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 3
A width() 0 4 1
A height() 0 4 1
A getDimension() 0 4 2
1
<?php
2
3
namespace League\CLImate\Util;
4
5
use League\CLImate\Util\System\SystemFactory;
6
use League\CLImate\Util\System\System;
7
8
class UtilFactory
9
{
10
    /**
11
     * A instance of the appropriate System class
12
     *
13
     * @var \League\CLImate\Util\System\System
14
     */
15
16
    public $system;
17
18
    /**
19
     * A instance of the Cursor class
20
     *
21
     * @var \League\CLImate\Util\Cursor
22
     */
23
    public $cursor;
24
25 948
    public function __construct(System $system = null, Cursor $cursor = null)
26
    {
27 948
        $this->system = $system ?: SystemFactory::getInstance();
28 948
        $this->cursor = $cursor ?: new Cursor();
29 948
    }
30
31
    /**
32
     * Get the width of the terminal
33
     *
34
     * @return integer
35
     */
36
37 96
    public function width()
38
    {
39 96
        return (int) $this->getDimension($this->system->width(), 80);
40
    }
41
42
    /**
43
     * Get the height of the terminal
44
     *
45
     * @return integer
46
     */
47
48
    public function height()
49
    {
50
        return (int) $this->getDimension($this->system->height(), 25);
51
    }
52
53
    /**
54
     * Determine if the value is numeric, fallback to a default if not
55
     *
56
     * @param integer|null $dimension
57
     * @param integer $default
58
     *
59
     * @return integer
60
     */
61
62 96
    protected function getDimension($dimension, $default)
63
    {
64 96
        return (is_numeric($dimension)) ? $dimension : $default;
65
    }
66
}
67