ArticleDiscussionsMapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 38.89 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 14
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDbAdapter() 0 4 1
A getPaginationSelect() 0 8 1
A get() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Article\Mapper;
6
7
use Article\Entity\ArticleType;
8
use Zend\Db\Adapter\Adapter;
9
use Zend\Db\Adapter\AdapterAwareInterface;
10
use Zend\Db\TableGateway\AbstractTableGateway;
11
12
class ArticleDiscussionsMapper extends AbstractTableGateway implements AdapterAwareInterface
13
{
14
    protected $table = 'article_discussions';
15
16
    public function setDbAdapter(Adapter $adapter)
17
    {
18
        $this->adapter = $adapter;
19
    }
20
21
    /**
22
     * @return \Zend\Db\Sql\Select
23
     */
24
    public function getPaginationSelect()
25
    {
26
        return $this->getSql()->select()
27
            ->columns(['title', 'body'])
28
            ->join('articles', 'article_discussions.article_uuid = articles.article_uuid')
29
            ->where(['articles.type' => ArticleType::DISCUSSION])
30
            ->order(['created_at' => 'desc']);
31
    }
32
33 View Code Duplication
    public function get($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $select = $this->getSql()->select()
36
            ->columns(['title', 'body'])
37
            ->join('articles', 'article_discussions.article_uuid = articles.article_uuid')
38
            ->join(
39
                'category', 'category.category_uuid = articles.category_uuid',
40
                ['category_slug' => 'slug', 'category_name' => 'name', 'category_id'], 'left'
41
            )
42
            ->join('admin_users', 'admin_users.admin_user_uuid = articles.admin_user_uuid', ['admin_user_id'], 'left')
43
            ->where(['articles.article_id' => $id]);
44
45
        return $this->selectWith($select)->current();
46
    }
47
}
48