Code Duplication    Length = 36-36 lines in 2 locations

lib/Db/NotebookMapper.php 2 locations

@@ 46-81 (lines=36) @@
43
	 * @param bool|int $deleted
44
	 * @return Notebook[]|Notebook
45
	 */
46
	public function find($notebook_id, $user_id = null, $deleted = false) {
47
		$params = [];
48
		$where = [];
49
		if($notebook_id){
50
			$where[] = 'g.id= ?';
51
			$params[] = $notebook_id;
52
		}
53
54
		if ($user_id !== null) {
55
			$params[] = $user_id;
56
			$where[] = 'g.uid = ?';
57
		}
58
59
		if ($deleted !== false) {
60
			$params[] = $deleted;
61
			$where[] = 'g.deleted = ?';
62
		}
63
		$where = implode(' AND ', $where);
64
		if($where){
65
			$where = 'WHERE '. $where;
66
		}
67
		$sql = "SELECT g.*, g.guid as guid, COUNT(n.id) as note_count FROM *PREFIX*nextnote_groups g LEFT JOIN *PREFIX*nextnote_notes n ON g.name=n.grouping $where  GROUP BY g.id";
68
		/**
69
		 * @var $results Notebook[]
70
		 */
71
		$results = [];
72
		foreach ($this->execute($sql, $params)->fetchAll() as $item) {
73
			$results[] = $this->makeEntityFromDBResult($item);
74
		}
75
//		var_dump($results);
76
		if(count($results) === 1){
77
			return reset($results);
78
		}
79
80
		return $results;
81
	}
82
83
	/**
84
	 * @param $group_name
@@ 89-124 (lines=36) @@
86
	 * @param bool $deleted
87
	 * @return Notebook[]|Notebook
88
	 */
89
	public function findByName($group_name, $user_id = null, $deleted = false) {
90
		$params = [];
91
		$where = [];
92
		if($group_name){
93
			$where[] = 'g.name = ?';
94
			$params[] = $group_name;
95
		}
96
97
		if ($user_id) {
98
			$params[] = $user_id;
99
			$where[] = 'g.uid = ?';
100
		}
101
102
		if ($deleted !== false) {
103
			$params[] = $deleted;
104
			$where[] = 'g.deleted = ?';
105
		}
106
		$where = implode(' AND ', $where);
107
		if($where){
108
			$where = 'WHERE '. $where;
109
		}
110
		$sql = "SELECT g.*, COUNT(n.id) as note_count FROM *PREFIX*nextnote_groups g LEFT JOIN *PREFIX*nextnote_notes n ON g.name=n.grouping $where  GROUP BY g.id";
111
		/**
112
		 * @var $results Notebook[]
113
		 */
114
		$results = [];
115
		foreach ($this->execute($sql, $params)->fetchAll() as $item) {
116
			$results[] = $this->makeEntityFromDBResult($item);
117
		}
118
119
		if(count($results) === 1){
120
			return reset($results);
121
		}
122
123
		return $results;
124
	}
125
126
   	/**
127
	 * Creates a group