Code Duplication    Length = 25-28 lines in 4 locations

src/services/Model.php 1 location

@@ 236-260 (lines=25) @@
233
     * @param string|null $toScenario
234
     * @return BaseModel|null
235
     */
236
    public function findById(int $id, string $toScenario = null)
237
    {
238
239
        // Check cache
240
        if (!$model = $this->findCacheById($id)) {
241
242
            // Find record in db
243
            if ($record = $this->findRecordById($id)) {
244
245
                // Perhaps in cache
246
                $model = $this->findByRecord($record, $toScenario);
247
248
            } else {
249
250
                $this->_cacheById[$id] = null;
251
252
                return null;
253
254
            }
255
256
        }
257
258
        return $model;
259
260
    }
261
262
    /**
263
     * @param int $id

src/services/ModelByHandle.php 1 location

@@ 66-90 (lines=25) @@
63
     * @param string|null $toScenario
64
     * @return ModelWithHandle|null
65
     */
66
    public function findByHandle(string $handle, string $toScenario = null)
67
    {
68
69
        // Check cache
70
        if (!$model = $this->findCacheByHandle($handle)) {
71
72
            // Find record in db
73
            if ($record = $this->findRecordByHandle($handle)) {
74
75
                /** @var ModelWithHandle $model */
76
                $model = $this->findByRecord($record, $toScenario);
77
78
            } else {
79
80
                $this->_cacheByHandle[$handle] = null;
81
82
                return null;
83
84
            }
85
86
        }
87
88
        return $model;
89
90
    }
91
92
    /**
93
     * @param string $handle

src/services/Object.php 1 location

@@ 233-260 (lines=28) @@
230
     * @param string|null $toScenario
231
     * @return BaseObject|null
232
     */
233
    public function findById(int $id, string $toScenario = null)
234
    {
235
236
        // Check cache
237
        if (!$object = $this->findCacheById($id)) {
238
239
            // Find record in db
240
            if ($record = $this->findRecordByCondition(
241
                ['id' => $id]
242
            )
243
            ) {
244
245
                // Perhaps in cache
246
                $object = $this->findByRecord($record, $toScenario);
247
248
            } else {
249
250
                $this->_cacheById[$id] = null;
251
252
                return null;
253
254
            }
255
256
        }
257
258
        return $object;
259
260
    }
261
262
    /**
263
     * @param int $id

src/services/ObjectByHandle.php 1 location

@@ 57-81 (lines=25) @@
54
     * @param string|null $toScenario
55
     * @return ObjectWithHandle|null
56
     */
57
    public function findByHandle(string $handle, string $toScenario = null)
58
    {
59
60
        // Check cache
61
        if (!$object = $this->findCacheByHandle($handle)) {
62
63
            // Find record in db
64
            if ($record = $this->findRecordByHandle($handle)) {
65
66
                /** @var ObjectWithHandle $object */
67
                $object = $this->findByRecord($record, $toScenario);
68
69
            } else {
70
71
                $this->_cacheByHandle[$handle] = null;
72
73
                return null;
74
75
            }
76
77
        }
78
79
        return $object;
80
81
    }
82
83
    /**
84
     * @param string $handle