Passed
Push — master ( 671b4b...06a963 )
by Gabriel
04:41
created

DownloadStatsProcess   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 23
c 1
b 0
f 0
dl 0
loc 62
ccs 0
cts 28
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A getLastLettersFromDownloads() 0 13 1
A handle() 0 5 3
A processForManager() 0 14 4
1
<?php
2
3
namespace ByTIC\DocumentGenerator\PdfLetters\Actions;
4
5
use ByTIC\DocumentGenerator\PdfLetters\Models\Downloads\DownloadsTrait;
6
use ByTIC\DocumentGenerator\PdfLetters\Models\PdfLetters\PdfLettersTrait;
7
use ByTIC\DocumentGenerator\PdfLetters\PdfLettersManager;
8
use Nip\MailModule\Models\EmailsTable\EmailsTrait;
0 ignored issues
show
Bug introduced by
The type Nip\MailModule\Models\EmailsTable\EmailsTrait 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 Nip\Records\AbstractModels\RecordManager;
10
use Nip\Records\Locator\ModelLocator;
11
12
/**
13
 * Class DownloadStatsProcess
14
 * @package ByTIC\DocumentGenerator\PdfLetters\Actions
15
 */
16
class DownloadStatsProcess
17
{
18
19
    /**
20
     * @var PdfLettersManager[]
21
     */
22
    protected $managers = [];
23
24
    /**
25
     * DownloadStatsProcess constructor.
26
     * @param array $managers
27
     */
28
    public function __construct(array $managers = null)
29
    {
30
        $this->managers = is_array($managers) ? $managers : app('dg.pdf-letters.manager')->getManagerClasses();
31
    }
32
33
    public function handle()
34
    {
35
        foreach ($this->managers as $manager) {
36
            $manager = is_object($manager) ? $manager : ModelLocator::get($manager);
37
            $this->processForManager($manager);
0 ignored issues
show
Bug introduced by
It seems like $manager can also be of type ByTIC\DocumentGenerator\...tters\PdfLettersManager; however, parameter $letterManager of ByTIC\DocumentGenerator\...ss::processForManager() does only seem to accept Nip\Records\AbstractModels\RecordManager, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            $this->processForManager(/** @scrutinizer ignore-type */ $manager);
Loading history...
38
        }
39
    }
40
41
    /**
42
     * @param RecordManager|PdfLettersTrait $letterManager
43
     */
44
    protected function processForManager(RecordManager $letterManager)
45
    {
46
        if (!$letterManager->hasRelation('Downloads')) {
47
            return;
48
        }
49
        $downloadsManager = $letterManager->getDownloadsManager();
50
        $letters = $this->getLastLettersFromDownloads($letterManager, $downloadsManager);
0 ignored issues
show
Bug introduced by
It seems like $downloadsManager can also be of type true; however, parameter $downloadsManager of ByTIC\DocumentGenerator\...tLettersFromDownloads() does only seem to accept ByTIC\DocumentGenerator\...actModels\RecordManager, maybe add an additional type check? ( Ignorable by Annotation )

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

50
        $letters = $this->getLastLettersFromDownloads($letterManager, /** @scrutinizer ignore-type */ $downloadsManager);
Loading history...
51
52
        $statsManager = $letterManager->getStatsManager();
53
        foreach ($letters as $letter) {
54
            if ($downloadsManager->shouldTrackLetter($letter)) {
0 ignored issues
show
Bug introduced by
The method shouldTrackLetter() does not exist on Nip\Records\Collections\Collection. ( Ignorable by Annotation )

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

54
            if ($downloadsManager->/** @scrutinizer ignore-call */ shouldTrackLetter($letter)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
                continue;
56
            }
57
            $statsManager->compileForLetter($letter);
0 ignored issues
show
Bug introduced by
The method compileForLetter() does not exist on Nip\Records\Collections\Collection. ( Ignorable by Annotation )

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

57
            $statsManager->/** @scrutinizer ignore-call */ 
58
                           compileForLetter($letter);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
        }
59
    }
60
61
    /**
62
     * @param PdfLettersTrait|RecordManager $letterManager
63
     * @param DownloadsTrait|RecordManager $downloadsManager
64
     */
65
    protected function getLastLettersFromDownloads($letterManager, $downloadsManager)
66
    {
67
        $letterPK = $letterManager->getRelation('Downloads')->getFK();
0 ignored issues
show
Bug introduced by
It seems like getFK() 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

67
        $letterPK = $letterManager->getRelation('Downloads')->/** @scrutinizer ignore-call */ getFK();
Loading history...
Bug introduced by
It seems like getRelation() 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

67
        $letterPK = $letterManager->/** @scrutinizer ignore-call */ getRelation('Downloads')->getFK();
Loading history...
Bug introduced by
The method getFK() does not exist on Nip\Records\Collections\Collection. Did you maybe mean get()? ( Ignorable by Annotation )

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

67
        $letterPK = $letterManager->getRelation('Downloads')->/** @scrutinizer ignore-call */ getFK();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
69
        $queryDownloads = $downloadsManager->newSelectQuery();
0 ignored issues
show
Bug introduced by
It seems like newSelectQuery() 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

69
        /** @scrutinizer ignore-call */ 
70
        $queryDownloads = $downloadsManager->newSelectQuery();
Loading history...
70
        $queryDownloads->setCols($letterPK);
71
        $queryDownloads->group($letterPK);
72
        $queryDownloads->limit(10);
73
74
        $queryLetters = $letterManager->newSelectQuery();
75
        $queryLetters->where('id IN ?', $queryDownloads);
0 ignored issues
show
Bug introduced by
$queryDownloads of type Nip\Database\Query\Select is incompatible with the type array expected by parameter $values of Nip\Database\Query\AbstractQuery::where(). ( Ignorable by Annotation )

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

75
        $queryLetters->where('id IN ?', /** @scrutinizer ignore-type */ $queryDownloads);
Loading history...
76
77
        return $letterManager->findByQuery($queryLetters);
0 ignored issues
show
Bug introduced by
The method findByQuery() does not exist on ByTIC\DocumentGenerator\...Letters\PdfLettersTrait. Did you maybe mean findOneByQuery()? ( Ignorable by Annotation )

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

77
        return $letterManager->/** @scrutinizer ignore-call */ findByQuery($queryLetters);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
    }
79
}
80