Code Duplication    Length = 33-33 lines in 2 locations

lib/Db/NotebookMapper.php 2 locations

@@ 40-72 (lines=33) @@
37
	}
38
39
40
	public function find($group_id, $user_id = null, $deleted = false) {
41
		$params = [];
42
		$where = [];
43
		if($group_id){
44
			$where[] = 'g.id= ?';
45
			$params[] = $group_id;
46
		}
47
48
		if ($user_id) {
49
			$params[] = $user_id;
50
			$where[] = 'g.uid = ?';
51
		}
52
53
		if ($deleted !== false) {
54
			$params[] = $deleted;
55
			$where[] = 'g.deleted = ?';
56
		}
57
		$where = implode(' AND ', $where);
58
		if($where){
59
			$where = 'WHERE '. $where;
60
		}
61
		$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";
62
		$results = [];
63
		foreach ($this->execute($sql, $params)->fetchAll() as $item) {
64
			$results[] = $this->makeEntityFromDBResult($item);
65
		}
66
//		var_dump($results);
67
		if(count($results) === 1){
68
			return reset($results);
69
		}
70
71
		return $results;
72
	}
73
74
75
	public function findByName($group_name, $user_id = null, $deleted = false) {
@@ 75-107 (lines=33) @@
72
	}
73
74
75
	public function findByName($group_name, $user_id = null, $deleted = false) {
76
		$params = [];
77
		$where = [];
78
		if($group_name){
79
			$where[] = 'g.name = ?';
80
			$params[] = $group_name;
81
		}
82
83
		if ($user_id) {
84
			$params[] = $user_id;
85
			$where[] = 'g.uid = ?';
86
		}
87
88
		if ($deleted !== false) {
89
			$params[] = $deleted;
90
			$where[] = 'g.deleted = ?';
91
		}
92
		$where = implode(' AND ', $where);
93
		if($where){
94
			$where = 'WHERE '. $where;
95
		}
96
		$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";
97
		$results = [];
98
		foreach ($this->execute($sql, $params)->fetchAll() as $item) {
99
			$results[] = $this->makeEntityFromDBResult($item);
100
		}
101
102
		if(count($results) === 1){
103
			return reset($results);
104
		}
105
106
		return $results;
107
	}
108
109
   	/**
110
	 * Creates a group