Failed Conditions
Pull Request — master (#153)
by Alexander
02:32
created

AbstractRepositoryCollectorPlugin::parse()   B

Complexity

Conditions 8
Paths 12

Size

Total Lines 41
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 8.0069

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 41
ccs 20
cts 21
cp 0.9524
rs 8.4444
cc 8
nc 12
nop 1
crap 8.0069
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
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IOverwriteAwarePlugin;
16
17
abstract class AbstractRepositoryCollectorPlugin extends AbstractPlugin implements IRepositoryCollectorPlugin
18
{
19
20
	/**
21
	 * Parse log entries.
22
	 *
23
	 * @param \SimpleXMLElement $log Log.
24
	 *
25
	 * @return void
26
	 */
27 31
	public function parse(\SimpleXMLElement $log)
28
	{
29 31
		$this->database->beginTransaction();
30
31 31
		$last_processed_revision = null;
32 31
		$last_revision = $this->getLastRevision();
33
34 31
		if ( $this instanceof IOverwriteAwarePlugin && $this->isOverwriteMode() ) {
35 4
			foreach ( $log->logentry as $log_entry ) {
36 4
				$revision = (int)$log_entry['revision'];
37
38 4
				$this->remove($revision);
39 4
				$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

39
				$this->doParse($revision, /** @scrutinizer ignore-type */ $log_entry);
Loading history...
40
41
				// When revision appeared only after overwrite parsing process.
42 4
				if ( $revision > $last_revision ) {
43
					$last_processed_revision = $revision;
44
				}
45
			}
46
		}
47
		else {
48 27
			foreach ( $log->logentry as $log_entry ) {
49 27
				$revision = (int)$log_entry['revision'];
50
51
				// Don't handle same revision twice.
52 27
				if ( $revision <= $last_revision ) {
53 3
					continue;
54
				}
55
56 24
				$this->doParse($revision, $log_entry);
57 24
				$last_processed_revision = $revision;
58
			}
59
		}
60
61 31
		if ( isset($last_processed_revision) ) {
62 24
			$this->setLastRevision($last_processed_revision);
63
		}
64
65 31
		$this->database->commit();
66
67 31
		$this->freeMemoryAutomatically();
68
	}
69
70
	/**
71
	 * Does actual parsing.
72
	 *
73
	 * @param integer           $revision  Revision.
74
	 * @param \SimpleXMLElement $log_entry Log Entry.
75
	 *
76
	 * @return void
77
	 */
78
	abstract protected function doParse($revision, \SimpleXMLElement $log_entry);
79
80
	/**
81
	 * Removes changes plugin made based on a given revision.
82
	 *
83
	 * @param integer $revision Revision.
84
	 *
85
	 * @return void
86
	 */
87
	abstract protected function remove($revision);
88
89
	/**
90
	 * Returns revision query flags.
91
	 *
92
	 * @return array
93
	 */
94 1
	public function getRevisionQueryFlags()
95
	{
96 1
		return array();
97
	}
98
99
}
100