Code Duplication    Length = 13-17 lines in 4 locations

src/tomzx/IRCStats/Inserter.php 2 locations

@@ 68-80 (lines=13) @@
65
		]);
66
	}
67
68
	protected function insertChannel($targetNetwork, $channel)
69
	{
70
		$db = $this->getDatabase();
71
		$targetChannel = $db->table('channels')->select('id')->where('network_id', '=', $targetNetwork)->where('channel', '=', $channel)->first();
72
		if ($targetChannel) {
73
			return $targetChannel->id;
74
		}
75
76
		return $db->table('channels')->insertGetId([
77
			'network_id' => $targetNetwork,
78
			'channel' => $channel,
79
		]);
80
	}
81
82
	protected function insertNick($targetNetwork, $nick)
83
	{
@@ 82-94 (lines=13) @@
79
		]);
80
	}
81
82
	protected function insertNick($targetNetwork, $nick)
83
	{
84
		$db = $this->getDatabase();
85
		$targetNick = $db->table('nicks')->select('id')->where('network_id', '=', $targetNetwork)->where('nick', '=', $nick)->first();
86
		if ($targetNick) {
87
			return $targetNick->id;
88
		}
89
90
		return $db->table('nicks')->insertGetId([
91
			'network_id' => $targetNetwork,
92
			'nick' => $nick,
93
		]);
94
	}
95
96
	public function insertLog($targetChannel, $targetNick, $timestamp, $message)
97
	{

src/tomzx/IRCStats/Parser.php 2 locations

@@ 82-98 (lines=17) @@
79
	 * @param string                          $channel
80
	 * @return int
81
	 */
82
	protected function getChannelId(Connection $db, $networkId, $channel)
83
	{
84
		$targetChannel = $db->table('channels')
85
			->select('id')
86
			->where('network_id', '=', $networkId)
87
			->where('channel', '=', $channel)
88
			->first();
89
90
		if ($targetChannel) {
91
			return $targetChannel['id'];
92
		} else {
93
			return $db->table('channels')->insertGetId([
94
				'network_id' => $networkId,
95
				'channel'    => $channel,
96
			]);
97
		}
98
	}
99
100
	/**
101
	 * @param \Illuminate\Database\Connection $db
@@ 106-122 (lines=17) @@
103
	 * @param string                          $nick
104
	 * @return int
105
	 */
106
	protected function getNickId(Connection $db, $channelId, $nick)
107
	{
108
		$targetNick = $db->table('nicks')
109
			->select('id')
110
			->where('channel_id', '=', $channelId)
111
			->where('nick', '=', $nick)
112
			->first();
113
114
		if ($targetNick) {
115
			return $targetNick['id'];
116
		} else {
117
			return $db->table('nicks')->insertGetId([
118
				'channel_id' => $channelId,
119
				'nick'       => $nick,
120
			]);
121
		}
122
	}
123
}
124