MergeChunks::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 3
c 2
b 1
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Jobtech\LaravelChunky\Jobs;
4
5
use Illuminate\Bus\Queueable;
0 ignored issues
show
Bug introduced by
The type Illuminate\Bus\Queueable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Foundation\Bus\Dispatchable;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Bus\Dispatchable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Illuminate\Queue\InteractsWithQueue;
0 ignored issues
show
Bug introduced by
The type Illuminate\Queue\InteractsWithQueue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Illuminate\Queue\SerializesModels;
0 ignored issues
show
Bug introduced by
The type Illuminate\Queue\SerializesModels was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Jobtech\LaravelChunky\Exceptions\ChunksIntegrityException;
11
use Jobtech\LaravelChunky\Facades\Chunky;
12
13
class MergeChunks implements ShouldQueue
14
{
15
    use Dispatchable;
16
    use InteractsWithQueue;
17
    use Queueable;
18
    use SerializesModels;
19
20
    private string $chunks_folder;
21
22
    private string $merge_path;
23
24
    private int $chunk_size;
25
26
    private int $total_size;
27
28
    /**
29
     * Create a new job instance.
30
     *
31
     * @param string $chunks_folder
32
     * @param string $merge_path
33
     * @param int $chunk_size
34
     * @param int $total_size
35
     */
36
    public function __construct(string $chunks_folder, string $merge_path, int $chunk_size, int $total_size)
37
    {
38
        $this->chunks_folder = $chunks_folder;
39
        $this->merge_path = $merge_path;
40
        $this->chunk_size = $chunk_size;
41
        $this->total_size = $total_size;
42
    }
43
44
    /**
45
     * Execute the job.
46
     *
47
     * @return void
48
     */
49
    public function handle()
50
    {
51
        if (! Chunky::checkChunksIntegrity($this->chunks_folder, $this->chunk_size, $this->total_size)) {
52
            throw new ChunksIntegrityException('Chunks total file size doesnt match with original file size');
53
        }
54
55
        Chunky::merge($this->chunks_folder, $this->merge_path);
56
    }
57
}
58