Passed
Push — main ( e5d18b...282b2b )
by Sugeng
03:08
created

ChecksumAdapterTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checksum() 0 12 2
1
<?php
2
3
namespace diecoding\flysystem\traits;
4
5
use League\Flysystem\Config;
6
use League\Flysystem\UnableToProvideChecksum;
7
8
/**
9
 * Trait ChecksumAdapterTrait for Adapter
10
 * 
11
 * @link      https://sugengsulistiyawan.my.id/
12
 * @author    Sugeng Sulistiyawan <[email protected]>
13
 * @copyright Copyright (c) 2023
14
 */
15
trait ChecksumAdapterTrait
16
{
17
    public function checksum(string $path, Config $config): string
18
    {
19
        $algo = $config->get('checksum_algo', 'md5');
20
        $contents = $this->read($path);
0 ignored issues
show
Bug introduced by
It seems like read() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        /** @scrutinizer ignore-call */ 
21
        $contents = $this->read($path);
Loading history...
21
        error_clear_last();
22
        $checksum = @hash($algo, $contents);
23
24
        if ($checksum === false) {
25
            throw new UnableToProvideChecksum(error_get_last()['message'] ?? '', $path);
26
        }
27
28
        return $checksum;
29
    }
30
}