Failed Conditions
Push — master ( 7ce495...e5509d )
by Alexander
02:41
created

AbstractRepositoryCollectorPlugin::parse()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 9.8333
c 0
b 0
f 0
cc 4
nc 6
nop 1
crap 4
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin;
12
13
14
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\AbstractPlugin;
15
16
abstract class AbstractRepositoryCollectorPlugin extends AbstractPlugin implements IRepositoryCollectorPlugin
17
{
18
19
	/**
20
	 * Parse log entries.
21
	 *
22
	 * @param \SimpleXMLElement $log Log.
23
	 *
24
	 * @return void
25
	 */
26 27
	public function parse(\SimpleXMLElement $log)
27
	{
28 27
		$this->database->beginTransaction();
29
30 27
		$last_processed_revision = null;
31 27
		$last_revision = $this->getLastRevision();
32
33 27
		foreach ( $log->logentry as $log_entry ) {
34 27
			$revision = (int)$log_entry['revision'];
35
36
			// Don't handle same revision twice.
37 27
			if ( $revision <= $last_revision ) {
38 3
				continue;
39
			}
40
41 24
			$this->doParse($revision, $log_entry);
0 ignored issues
show
Bug introduced by
It seems like $log_entry can also be of type null; however, parameter $log_entry of ConsoleHelpers\SVNBuddy\...lectorPlugin::doParse() does only seem to accept SimpleXMLElement, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
			$this->doParse($revision, /** @scrutinizer ignore-type */ $log_entry);
Loading history...
42 24
			$last_processed_revision = $revision;
43
		}
44
45 27
		if ( isset($last_processed_revision) ) {
46 24
			$this->setLastRevision($last_processed_revision);
47
		}
48
49 27
		$this->database->commit();
50
51 27
		$this->freeMemoryAutomatically();
52
	}
53
54
	/**
55
	 * Does actual parsing.
56
	 *
57
	 * @param integer           $revision  Revision.
58
	 * @param \SimpleXMLElement $log_entry Log Entry.
59
	 *
60
	 * @return void
61
	 */
62
	abstract protected function doParse($revision, \SimpleXMLElement $log_entry);
63
64
	/**
65
	 * Returns revision query flags.
66
	 *
67
	 * @return array
68
	 */
69 1
	public function getRevisionQueryFlags()
70
	{
71 1
		return array();
72
	}
73
74
}
75