Passed
Pull Request — master (#2194)
by Janko
19:29 queued 12:15
created

TradeTransactionRepository::truncateAllTradeTransactions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Doctrine\ORM\Query\ResultSetMapping;
9
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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 Stu\Component\Game\TimeConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\TimeConstants 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...
11
use Stu\Orm\Entity\TradeTransaction;
12
13
/**
14
 * @extends EntityRepository<TradeTransaction>
15
 */
16
final class TradeTransactionRepository extends EntityRepository implements TradeTransactionRepositoryInterface
17
{
18
    #[Override]
19
    public function prototype(): TradeTransaction
20
    {
21
        return new TradeTransaction();
22
    }
23
24
    #[Override]
25
    public function save(TradeTransaction $tradeTransaction): void
26
    {
27
        $em = $this->getEntityManager();
28
29
        $em->persist($tradeTransaction);
30
    }
31
32 1
    #[Override]
33
    public function getTradePostsTop10(): array
34
    {
35 1
        $rsm = new ResultSetMapping();
36 1
        $rsm->addScalarResult('id', 'id', 'integer');
37 1
        $rsm->addScalarResult('name', 'name');
38 1
        $rsm->addScalarResult('transactions', 'transactions', 'integer');
39 1
        return $this
40 1
            ->getEntityManager()
41 1
            ->createNativeQuery(
42 1
                'SELECT tp.id, tp.name, COUNT(tt.tradepost_id) as transactions
43
                FROM stu_trade_transaction tt
44
                LEFT JOIN stu_trade_posts tp ON tp.id = tt.tradepost_id
45
                WHERE tt.date > :sevendays AND tt.tradepost_id > 0 AND tp.id > 0
46 1
                GROUP BY tp.id ORDER BY transactions DESC LIMIT 10',
47 1
                $rsm
48 1
            )
49 1
            ->setParameters([
50 1
                'sevendays' => time() - TimeConstants::SEVEN_DAYS_IN_SECONDS
51 1
            ])
52 1
            ->getResult();
53
    }
54
}
55