Inspector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bankNumberOf() 0 8 1
A fileVersionOf() 0 14 2
1
<?php
2
3
namespace SmartCNAB\Support\File;
4
5
use RangeException;
6
7
/**
8
 * Files inspector.
9
 * Grab some util informations about files.
10
 */
11
class Inspector
12
{
13
    /**
14
     * Discover and return the bank number a file.
15
     *
16
     * @param  string  $path
17
     * @return integer
18
     */
19
    public static function bankNumberOf($path)
20
    {
21
        $file = fopen(realpath($path), 'r');
22
        $header = fgets($file);
23
        fclose($file);
24
25
        return substr($header, 76, 3);
26
    }
27
28
    /**
29
     * Discover and return a file CNAB version.
30
     *
31
     * @param  string  $path
32
     * @return integer
33
     * @throws \RangeException
34
     */
35
    public static function fileVersionOf($path)
36
    {
37
        $file = fopen(realpath($path), 'r');
38
        $header = fgets($file);
39
        fclose($file);
40
41
        $size = strlen(trim($header));
42
43
        if ( ! in_array($size, [240, 400])) {
44
            throw new RangeException('Invalid CNAB file version. Size ' . $size);
45
        }
46
47
        return $size;
48
    }
49
}
50