Code Duplication    Length = 23-24 lines in 4 locations

htdocs/src/Oc/FieldNotes/Persistence/FieldNoteRepository.php 1 location

@@ 117-139 (lines=23) @@
114
     * @throws RecordNotFoundException Thrown when no record is found
115
     * @return null|FieldNoteEntity
116
     */
117
    public function fetchOneBy(array $where = [])
118
    {
119
        $queryBuilder = $this->connection->createQueryBuilder()
120
            ->select('*')
121
            ->from(self::TABLE)
122
            ->setMaxResults(1);
123
124
        if (count($where) > 0) {
125
            foreach ($where as $column => $value) {
126
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
127
            }
128
        }
129
130
        $statement = $queryBuilder->execute();
131
132
        $result = $statement->fetch();
133
134
        if ($statement->rowCount() === 0) {
135
            throw new RecordNotFoundException('Record with given where clause not found');
136
        }
137
138
        return $this->getEntityFromDatabaseArray($result);
139
    }
140
141
    /**
142
     * Fetch latest user field note.

htdocs/src/Oc/GeoCache/Persistence/GeoCache/GeoCacheRepository.php 1 location

@@ 73-95 (lines=23) @@
70
     * @throws RecordNotFoundException Thrown when no record is found
71
     * @return null|GeoCacheEntity
72
     */
73
    public function fetchOneBy(array $where = [])
74
    {
75
        $queryBuilder = $this->connection->createQueryBuilder()
76
             ->select('*')
77
             ->from(self::TABLE)
78
             ->setMaxResults(1);
79
80
        if (count($where) > 0) {
81
            foreach ($where as $column => $value) {
82
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
83
            }
84
        }
85
86
        $statement = $queryBuilder->execute();
87
88
        $result = $statement->fetch();
89
90
        if ($statement->rowCount() === 0) {
91
            throw new RecordNotFoundException('Record with given where clause not found');
92
        }
93
94
        return $this->getEntityFromDatabaseArray($result);
95
    }
96
97
    /**
98
     * Fetches all GeoCaches by given where clause.

htdocs/src/Oc/GeoCache/Persistence/GeoCacheLog/GeoCacheLogRepository.php 1 location

@@ 72-94 (lines=23) @@
69
     * @throws RecordNotFoundException Thrown when no record is found
70
     * @return null|GeoCacheLogEntity
71
     */
72
    public function fetchOneBy(array $where = [])
73
    {
74
        $queryBuilder = $this->connection->createQueryBuilder()
75
             ->select('*')
76
             ->from(self::TABLE)
77
             ->setMaxResults(1);
78
79
        if (count($where) > 0) {
80
            foreach ($where as $column => $value) {
81
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
82
            }
83
        }
84
85
        $statement = $queryBuilder->execute();
86
87
        $result = $statement->fetch();
88
89
        if ($statement->rowCount() === 0) {
90
            throw new RecordNotFoundException('Record with given where clause not found');
91
        }
92
93
        return $this->getEntityFromDatabaseArray($result);
94
    }
95
96
    /**
97
     * Fetches all GeoCacheLogs by given where clause.

htdocs/src/Oc/Page/Persistence/PageRepository.php 1 location

@@ 46-69 (lines=24) @@
43
     * @throws RecordNotFoundException Thrown when no record is found
44
     * @return null|PageEntity
45
     */
46
    public function fetchOneBy(array $where = [])
47
    {
48
        $queryBuilder = $this->connection->createQueryBuilder()
49
            ->select('*')
50
            ->from(self::TABLE)
51
            ->setMaxResults(1);
52
53
54
        if (count($where) > 0) {
55
            foreach ($where as $column => $value) {
56
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
57
            }
58
        }
59
60
        $statement = $queryBuilder->execute();
61
62
        $result = $statement->fetch();
63
64
        if ($statement->rowCount() === 0) {
65
            throw new RecordNotFoundException('Record with given where clause not found');
66
        }
67
68
        return $this->getEntityFromDatabaseArray($result);
69
    }
70
71
    /**
72
     * Creates a page in the database.