Completed
Push — typo3v9 ( aea555...37a7d2 )
by Tomas Norre
06:20
created

AbstractRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A countAll() 0 10 1
A countAllByProcessId() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Domain\Repository;
6
7
/***************************************************************
8
 *  Copyright notice
9
 *
10
 *  (c) 2016 AOE GmbH <[email protected]>
11
 *
12
 *  All rights reserved
13
 *
14
 *  This script is part of the TYPO3 project. The TYPO3 project is
15
 *  free software; you can redistribute it and/or modify
16
 *  it under the terms of the GNU General Public License as published by
17
 *  the Free Software Foundation; either version 3 of the License, or
18
 *  (at your option) any later version.
19
 *
20
 *  The GNU General Public License can be found at
21
 *  http://www.gnu.org/copyleft/gpl.html.
22
 *
23
 *  This script is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU General Public License for more details.
27
 *
28
 *  This copyright notice MUST APPEAR in all copies of the script!
29
 ***************************************************************/
30
31
use TYPO3\CMS\Core\Database\ConnectionPool;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
use TYPO3\CMS\Extbase\Persistence\Repository;
34
35
/**
36
 * Class AbstractRepository
37
 *
38
 * @package AOE\Crawler\Domain\Repository
39
 */
40
abstract class AbstractRepository extends Repository
41
{
42
    /**
43
     * @var string table name
44
     */
45
    protected $tableName;
46
47
    /**
48
     * Counts all in repository
49
     *
50
     * @return integer
51
     */
52
    public function countAll()
53
    {
54
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
55
56
        return $queryBuilder
57
            ->count('*')
58
            ->from($this->tableName)
59
            ->execute()
60
            ->fetchColumn(0);
61
    }
62
63
    /**
64
     * @param string $processId
65
     *
66
     * @return bool|string
67
     */
68
    public function countAllByProcessId($processId)
69
    {
70
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
71
72
        return $queryBuilder
73
            ->count('*')
74
            ->from($this->tableName)
75
            ->where(
76
                $queryBuilder->expr()->eq('process_id', $queryBuilder->createNamedParameter($processId, \PDO::PARAM_STR))
77
            )
78
            ->execute()
79
            ->fetchColumn(0);
80
    }
81
}
82