Code Duplication    Length = 23-24 lines in 4 locations

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

@@ 49-72 (lines=24) @@
46
     *
47
     * @throws RecordNotFoundException Thrown when no record is found
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
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
     * Creates a page in the database.

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

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

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

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

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

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