• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

php-bug-catcher / bug-catcher / 20456731454

23 Dec 2025 09:21AM UTC coverage: 85.729% (-3.4%) from 89.142%
20456731454

push

github

web-flow
Merge pull request #17 from php-bug-catcher/selection

Added selection functionality to logs for batch proccesing

2 of 16 new or added lines in 3 files covered. (12.5%)

20 existing lines in 5 files now uncovered.

829 of 967 relevant lines covered (85.73%)

13.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/Repository/RecordRepository.php
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Jozef Môstka
5
 * Date: 31. 5. 2024
6
 * Time: 15:53
7
 */
8

9
namespace BugCatcher\Repository;
10

11
use BugCatcher\Entity\Project;
12
use BugCatcher\Entity\Record;
13
use BugCatcher\Enum\RecordEventType;
14
use BugCatcher\Event\RecordEvent;
15
use DateTimeImmutable;
16
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
17
use Doctrine\ORM\QueryBuilder;
18
use Doctrine\Persistence\ManagerRegistry;
19
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20

21
/**
22
 * @method Record|null find($id, $lockMode = null, $lockVersion = null)
23
 * @method Record|null findOneBy(array $criteria, array $orderBy = null)
24
 * @method Record[] findAll()
25
 * @method Record[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
26
 */
27
final class RecordRepository extends ServiceEntityRepository implements RecordRepositoryInterface
28
{
29
    public function __construct(
30
        ManagerRegistry $registry,
31
        protected EventDispatcherInterface $dispatcher,
32
    ) {
33
        parent::__construct($registry, Record::class);
108✔
34
    }
35

36
    /**
37
         * @param DateTimeImmutable $to
38
     * @param Project[] $projects
39
     */
40
    public function setStatusBetween(
41
        array $projects,
42
                DateTimeImmutable $from,
43
                DateTimeImmutable $to,
44
        string $newStatus,
45
        string $previousStatus = 'new',
46
                ?callable         $qbCreator = null
47
    ): void {
UNCOV
48
        $qb = $this->getUpdateStatusQB($newStatus, $from, $to, $previousStatus, $qbCreator);
×
49

UNCOV
50
        $qb
×
UNCOV
51
            ->andWhere("l.project IN (:projects)")
×
UNCOV
52
            ->setParameter('projects', array_map(fn(Project $s) => $s->getId()->toBinary(), $projects))
×
UNCOV
53
            ->getQuery()
×
UNCOV
54
            ->execute();
×
UNCOV
55
        $this->dispatcher->dispatch(new RecordEvent(null, RecordEventType::BATCH_UPDATED, $projects));
×
56
    }
57

58
    public function setStatus(
59
        Record $log,
60
                DateTimeImmutable $lastDate,
61
        string $newStatus,
62
        string $previousStatus = 'new',
63
        bool $flush = false,
64
                ?callable $qbCreator = null
65
    ): void {
66
        $qb = $this->getUpdateStatusQB($newStatus, $lastDate, new DateTimeImmutable(), $previousStatus, $qbCreator);
6✔
67
        $qb
6✔
68
            ->andWhere('l.hash = :hash')
6✔
69
            ->setParameter('hash', $log->getHash())
6✔
70
            ->getQuery()
6✔
71
            ->execute();
6✔
72
        $this->dispatcher->dispatch(new RecordEvent($log, RecordEventType::UPDATED, [$log->getProject()]));
6✔
73
        if ($flush) {
6✔
74
            $this->getEntityManager()->flush();
6✔
75
        }
76
    }
77

78
    protected function getUpdateStatusQB(
79
        string $newStatus,
80
                DateTimeImmutable $from,
81
                DateTimeImmutable $to,
82
        string $previousStatus,
83
                ?callable $qbCreator = null
84
    ): QueryBuilder {
85

86
        if ($qbCreator != null) {
6✔
87
            /** @var QueryBuilder $qb */
88
            $qb = call_user_func_array($qbCreator, [$newStatus, $from, $previousStatus]);
2✔
89
        } else {
90
            $qb = $this->createQueryBuilder('l');
4✔
91
        }
92
        $qb = $qb->update()
6✔
93
            ->set('l.status', "'{$newStatus}'")
6✔
94
            ->andWhere('l.date BETWEEN :from AND :to')
6✔
95
            ->andWhere('l.status = :status')
6✔
96
            ->setParameter('from', $from)
6✔
97
            ->setParameter('to', $to)
6✔
98
            ->setParameter('status', $previousStatus);
6✔
99

100
        return $qb;
6✔
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc