Completed
Branch master (23259a)
by Sergey
04:17 queued 48s
created

FileHelper::saveTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
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
        file_put_contents($destination, file_get_contents($source));
34
    }
35
}
36