FileHelper::getMimeType()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace seregazhuk\PinterestBot\Helpers;
4
5
use seregazhuk\PinterestBot\Exceptions\InvalidRequest;
6
7
class FileHelper
8
{
9
    /**
10
     * @param string $filePath
11
     * @return mixed
12
     * @throws InvalidRequest
13
     */
14
    public static function getMimeType($filePath)
15
    {
16
        if (!file_exists($filePath)) {
17
            throw new InvalidRequest("$filePath: failed to open file.");
18
        }
19
        
20
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
21
        $type = finfo_file($fileInfo, $filePath);
22
        finfo_close($fileInfo);
23
24
        return $type;
25
    }
26
27
    /**
28
     * @param string $source
29
     * @param string $destination
30
     */
31
    public static function saveTo($source, $destination)
32
    {
33
        copy($source, $destination);
34
    }
35
}
36