Network   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 26
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 5
1
<?php
2
3
namespace Posprint\Connectors;
4
5
/**
6
 * Class File
7
 * Create a binary file and writes the data line by line.
8
 * And it can also be used to provide direct connections to USB ports.
9
 *
10
 * @category  NFePHP
11
 * @package   Posprint
12
 * @copyright Copyright (c) 2016
13
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/posprint for the canonical source repository
16
 */
17
18
use Posprint\Connectors\ConnectorInterface;
19
use Posprint\Connectors\File;
20
use RuntimeException;
21
use InvalidArgumentException;
22
23
class Network extends File implements ConnectorInterface
24
{
25
    /**
26
     * Open a connection to a TCP/IP socket for ethernet printer connections
27
     *
28
     * @param  string $hostname
29
     * @param  int $port
30
     * @throws RuntimeException
31
     */
32 1
    public function __construct($hostname = '', $port = 9100)
33
    {
34 1
        parent::__construct();
35
        if (empty($hostname)) {
36
            throw new InvalidArgumentException("A hostname or a valid IP must be passed.");
37 1
        }
38
        if (empty($port) || ! is_numeric($port)) {
39
            $port = 9100;
40 1
        }
41 1
        $errno = 0;
42 1
        $errstr = '';
43 1
        $this->resource = @fsockopen($hostname, $port, $errno, $errstr);
44 1
        if ($this->resource === false) {
45
            throw new RuntimeException("Cannot initialise NetworkPrintConnector: " . $errstr);
46
        }
47
    }
48
}
49