Code Duplication    Length = 184-184 lines in 4 locations

local/devel/Repositories/MigrationVersionsRepository.php 1 location

@@ 9-192 (lines=184) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class MigrationVersionsRepository
10
{
11
    const TABLE = 'migration_versions';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return MigrationVersionsEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
                    ->select('*')
28
                    ->from(self::TABLE)
29
                    ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @param array $where
48
     * @return MigrationVersionsEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return MigrationVersionsEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param MigrationVersionsEntity $entity
109
     * @return MigrationVersionsEntity
110
     */
111
    public function create(MigrationVersionsEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->version = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param MigrationVersionsEntity $entity
131
     * @return MigrationVersionsEntity
132
     */
133
    public function update(MigrationVersionsEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['version' => $entity->version]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param MigrationVersionsEntity $entity
152
     * @return MigrationVersionsEntity
153
     */
154
    public function remove(MigrationVersionsEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['version' => $entity->version]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param MigrationVersionsEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(MigrationVersionsEntity $entity)
175
    {
176
        return [
177
        'version' => $entity->version,
178
        ];
179
    }
180
181
    /**
182
     * @param array $data
183
     * @return MigrationVersionsEntity
184
     */
185
    public function getEntityFromDatabaseArray(array $data)
186
    {
187
        $entity = new MigrationVersionsEntity();
188
        $entity->version = $data['version'];
189
190
        return $entity;
191
    }
192
}
193

local/devel/Repositories/OkapiCacheReadsRepository.php 1 location

@@ 9-192 (lines=184) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class OkapiCacheReadsRepository
10
{
11
    const TABLE = 'okapi_cache_reads';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return OkapiCacheReadsEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
                    ->select('*')
28
                    ->from(self::TABLE)
29
                    ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @param array $where
48
     * @return OkapiCacheReadsEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return OkapiCacheReadsEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param OkapiCacheReadsEntity $entity
109
     * @return OkapiCacheReadsEntity
110
     */
111
    public function create(OkapiCacheReadsEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->cacheKey = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param OkapiCacheReadsEntity $entity
131
     * @return OkapiCacheReadsEntity
132
     */
133
    public function update(OkapiCacheReadsEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['cache_key' => $entity->cacheKey]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param OkapiCacheReadsEntity $entity
152
     * @return OkapiCacheReadsEntity
153
     */
154
    public function remove(OkapiCacheReadsEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['cache_key' => $entity->cacheKey]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param OkapiCacheReadsEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(OkapiCacheReadsEntity $entity)
175
    {
176
        return [
177
        'cache_key' => $entity->cacheKey,
178
        ];
179
    }
180
181
    /**
182
     * @param array $data
183
     * @return OkapiCacheReadsEntity
184
     */
185
    public function getEntityFromDatabaseArray(array $data)
186
    {
187
        $entity = new OkapiCacheReadsEntity();
188
        $entity->cacheKey = $data['cache_key'];
189
190
        return $entity;
191
    }
192
}
193

local/devel/Repositories/PwDictRepository.php 1 location

@@ 9-192 (lines=184) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class PwDictRepository
10
{
11
    const TABLE = 'pw_dict';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return PwDictEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
                    ->select('*')
28
                    ->from(self::TABLE)
29
                    ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @param array $where
48
     * @return PwDictEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return PwDictEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param PwDictEntity $entity
109
     * @return PwDictEntity
110
     */
111
    public function create(PwDictEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->pw = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param PwDictEntity $entity
131
     * @return PwDictEntity
132
     */
133
    public function update(PwDictEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['pw' => $entity->pw]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param PwDictEntity $entity
152
     * @return PwDictEntity
153
     */
154
    public function remove(PwDictEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['pw' => $entity->pw]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param PwDictEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(PwDictEntity $entity)
175
    {
176
        return [
177
        'pw' => $entity->pw,
178
        ];
179
    }
180
181
    /**
182
     * @param array $data
183
     * @return PwDictEntity
184
     */
185
    public function getEntityFromDatabaseArray(array $data)
186
    {
187
        $entity = new PwDictEntity();
188
        $entity->pw = $data['pw'];
189
190
        return $entity;
191
    }
192
}
193

local/devel/Repositories/SearchIgnoreRepository.php 1 location

@@ 9-192 (lines=184) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SearchIgnoreRepository
10
{
11
    const TABLE = 'search_ignore';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SearchIgnoreEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
                    ->select('*')
28
                    ->from(self::TABLE)
29
                    ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @param array $where
48
     * @return SearchIgnoreEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return SearchIgnoreEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param SearchIgnoreEntity $entity
109
     * @return SearchIgnoreEntity
110
     */
111
    public function create(SearchIgnoreEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->word = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param SearchIgnoreEntity $entity
131
     * @return SearchIgnoreEntity
132
     */
133
    public function update(SearchIgnoreEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['word' => $entity->word]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param SearchIgnoreEntity $entity
152
     * @return SearchIgnoreEntity
153
     */
154
    public function remove(SearchIgnoreEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['word' => $entity->word]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param SearchIgnoreEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(SearchIgnoreEntity $entity)
175
    {
176
        return [
177
        'word' => $entity->word,
178
        ];
179
    }
180
181
    /**
182
     * @param array $data
183
     * @return SearchIgnoreEntity
184
     */
185
    public function getEntityFromDatabaseArray(array $data)
186
    {
187
        $entity = new SearchIgnoreEntity();
188
        $entity->word = $data['word'];
189
190
        return $entity;
191
    }
192
}
193