Code Duplication    Length = 198-198 lines in 3 locations

local/devel/Repositories/GeodbFloatdataRepository.php 1 location

@@ 9-206 (lines=198) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class GeodbFloatdataRepository
10
{
11
    const TABLE = 'geodb_floatdata';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeodbFloatdataEntity[]
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 GeodbFloatdataEntity
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 GeodbFloatdataEntity[]
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 GeodbFloatdataEntity $entity
109
     * @return GeodbFloatdataEntity
110
     */
111
    public function create(GeodbFloatdataEntity $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->locId = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param GeodbFloatdataEntity $entity
131
     * @return GeodbFloatdataEntity
132
     */
133
    public function update(GeodbFloatdataEntity $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
            ['loc_id' => $entity->locId]
145
        );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param GeodbFloatdataEntity $entity
152
     * @return GeodbFloatdataEntity
153
     */
154
    public function remove(GeodbFloatdataEntity $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
            ['loc_id' => $entity->locId]
163
        );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param GeodbFloatdataEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(GeodbFloatdataEntity $entity)
175
    {
176
        return [
177
            'loc_id' => $entity->locId,
178
            'float_val' => $entity->floatVal,
179
            'float_type' => $entity->floatType,
180
            'float_subtype' => $entity->floatSubtype,
181
            'valid_since' => $entity->validSince,
182
            'date_type_since' => $entity->dateTypeSince,
183
            'valid_until' => $entity->validUntil,
184
            'date_type_until' => $entity->dateTypeUntil,
185
        ];
186
    }
187
188
    /**
189
     * @param array $data
190
     * @return GeodbFloatdataEntity
191
     */
192
    public function getEntityFromDatabaseArray(array $data)
193
    {
194
        $entity = new GeodbFloatdataEntity();
195
        $entity->locId = (int) $data['loc_id'];
196
        $entity->floatVal = $data['float_val'];
197
        $entity->floatType = (int) $data['float_type'];
198
        $entity->floatSubtype = (int) $data['float_subtype'];
199
        $entity->validSince = new DateTime($data['valid_since']);
200
        $entity->dateTypeSince = (int) $data['date_type_since'];
201
        $entity->validUntil = new DateTime($data['valid_until']);
202
        $entity->dateTypeUntil = (int) $data['date_type_until'];
203
204
        return $entity;
205
    }
206
}
207

local/devel/Repositories/GeodbIntdataRepository.php 1 location

@@ 9-206 (lines=198) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class GeodbIntdataRepository
10
{
11
    const TABLE = 'geodb_intdata';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeodbIntdataEntity[]
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 GeodbIntdataEntity
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 GeodbIntdataEntity[]
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 GeodbIntdataEntity $entity
109
     * @return GeodbIntdataEntity
110
     */
111
    public function create(GeodbIntdataEntity $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->locId = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param GeodbIntdataEntity $entity
131
     * @return GeodbIntdataEntity
132
     */
133
    public function update(GeodbIntdataEntity $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
            ['loc_id' => $entity->locId]
145
        );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param GeodbIntdataEntity $entity
152
     * @return GeodbIntdataEntity
153
     */
154
    public function remove(GeodbIntdataEntity $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
            ['loc_id' => $entity->locId]
163
        );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param GeodbIntdataEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(GeodbIntdataEntity $entity)
175
    {
176
        return [
177
            'loc_id' => $entity->locId,
178
            'int_val' => $entity->intVal,
179
            'int_type' => $entity->intType,
180
            'int_subtype' => $entity->intSubtype,
181
            'valid_since' => $entity->validSince,
182
            'date_type_since' => $entity->dateTypeSince,
183
            'valid_until' => $entity->validUntil,
184
            'date_type_until' => $entity->dateTypeUntil,
185
        ];
186
    }
187
188
    /**
189
     * @param array $data
190
     * @return GeodbIntdataEntity
191
     */
192
    public function getEntityFromDatabaseArray(array $data)
193
    {
194
        $entity = new GeodbIntdataEntity();
195
        $entity->locId = (int) $data['loc_id'];
196
        $entity->intVal = (int) $data['int_val'];
197
        $entity->intType = (int) $data['int_type'];
198
        $entity->intSubtype = (int) $data['int_subtype'];
199
        $entity->validSince = new DateTime($data['valid_since']);
200
        $entity->dateTypeSince = (int) $data['date_type_since'];
201
        $entity->validUntil = new DateTime($data['valid_until']);
202
        $entity->dateTypeUntil = (int) $data['date_type_until'];
203
204
        return $entity;
205
    }
206
}
207

local/devel/Repositories/Map2ResultRepository.php 1 location

@@ 9-206 (lines=198) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class Map2ResultRepository
10
{
11
    const TABLE = 'map2_result';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return Map2ResultEntity[]
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 Map2ResultEntity
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 Map2ResultEntity[]
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 Map2ResultEntity $entity
109
     * @return Map2ResultEntity
110
     */
111
    public function create(Map2ResultEntity $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->resultId = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param Map2ResultEntity $entity
131
     * @return Map2ResultEntity
132
     */
133
    public function update(Map2ResultEntity $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
            ['result_id' => $entity->resultId]
145
        );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param Map2ResultEntity $entity
152
     * @return Map2ResultEntity
153
     */
154
    public function remove(Map2ResultEntity $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
            ['result_id' => $entity->resultId]
163
        );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param Map2ResultEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(Map2ResultEntity $entity)
175
    {
176
        return [
177
            'result_id' => $entity->resultId,
178
            'slave_id' => $entity->slaveId,
179
            'sqlchecksum' => $entity->sqlchecksum,
180
            'sqlquery' => $entity->sqlquery,
181
            'shared_counter' => $entity->sharedCounter,
182
            'request_counter' => $entity->requestCounter,
183
            'date_created' => $entity->dateCreated,
184
            'date_lastqueried' => $entity->dateLastqueried,
185
        ];
186
    }
187
188
    /**
189
     * @param array $data
190
     * @return Map2ResultEntity
191
     */
192
    public function getEntityFromDatabaseArray(array $data)
193
    {
194
        $entity = new Map2ResultEntity();
195
        $entity->resultId = (int) $data['result_id'];
196
        $entity->slaveId = (int) $data['slave_id'];
197
        $entity->sqlchecksum = (int) $data['sqlchecksum'];
198
        $entity->sqlquery = (string) $data['sqlquery'];
199
        $entity->sharedCounter = (int) $data['shared_counter'];
200
        $entity->requestCounter = (int) $data['request_counter'];
201
        $entity->dateCreated = new DateTime($data['date_created']);
202
        $entity->dateLastqueried = new DateTime($data['date_lastqueried']);
203
204
        return $entity;
205
    }
206
}
207