GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#936)
by Tom
02:28
created

File_Backup_Engine   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 11
Bugs 1 Features 0
Metric Value
wmc 9
c 11
b 1
f 0
lcom 1
cbo 4
dl 0
loc 101
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A set_excludes() 0 3 1
B get_files() 0 29 3
A verify_backup() 0 15 4
1
<?php
2
3
namespace HM\BackUpWordPress;
4
5
use Symfony\Component\Finder\Finder as Finder;
6
7
/**
8
 * The File Backup Engine type
9
 *
10
 * All File Backup Engine implementations should extend this class
11
 */
12
abstract class File_Backup_Engine extends Backup_Engine {
13
14
	/**
15
	 * The array of excludes rules
16
	 *
17
	 * @var array
18
	 */
19
	protected $excludes;
20
21
	/**
22
	 * Set the default backup filename.
23
	 */
24
	public function __construct() {
25
26
		parent::__construct();
27
28
		$this->set_backup_filename( implode( '-', array(
29
			str_ireplace( array( 'http://', 'https://', 'www' ), '', home_url() ),
30
			'backup',
31
			current_time( 'Y-m-d-H-i-s' )
32
		) ) . '.zip' );
33
34
		$this->excludes = new Excludes;
0 ignored issues
show
Documentation Bug introduced by
It seems like new \HM\BackUpWordPress\Excludes() of type object<HM\BackUpWordPress\Excludes> is incompatible with the declared type array of property $excludes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
36
	}
37
38
	/**
39
	 * Set the excludes rules for the backup.
40
	 *
41
	 * @param array $excludes The exclude rules.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $excludes not be Excludes?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
42
	 */
43
	public function set_excludes( Excludes $excludes ) {
44
		$this->excludes = $excludes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $excludes of type object<HM\BackUpWordPress\Excludes> is incompatible with the declared type array of property $excludes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
	}
46
47
	/**
48
	 * Returns a Finder instance for the files that will be included in the
49
	 * backup.
50
	 *
51
	 * By default we ignore unreadable files and directories as well as, common
52
	 * version control folders / files, "Dot" files and anything matching the
53
	 * exclude rules.
54
	 *
55
	 * @uses Finder
56
	 * @return Finder The Finder iterator of all files to be included
57
	 */
58
	public function get_files() {
59
60
		$finder = new Finder();
61
62
		$finder->followLinks( true );
0 ignored issues
show
Unused Code introduced by
The call to Finder::followLinks() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
63
		$finder->ignoreDotFiles( false );
64
		$finder->ignoreVCS( true );
65
		$finder->ignoreUnreadableDirs( true );
66
67
		// Skip unreadable files too
68
		$finder->filter(
69
			function ( \SplFileInfo $file ) {
70
				if ( ! $file->isReadable() ) {
71
					return false;
72
				}
73
			}
74
		);
75
76
		// Finder expects exclude rules to be in a regex format
77
		$exclude_rules = $this->excludes->get_excludes_for_regex();
0 ignored issues
show
Bug introduced by
The method get_excludes_for_regex cannot be called on $this->excludes (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
78
79
		// Skips folders/files that match default exclude patterns
80
		foreach ( $exclude_rules as $exclude ) {
81
			$finder->notPath( $exclude );
82
		}
83
84
		return $finder->in( Path::get_root() );
85
86
	}
87
88
	/**
89
	 * Verify that the file backup completed successfully.
90
	 *
91
	 * This should be called from backup method of any final file backup engine
92
	 * implementations.
93
	 *
94
	 * @return bool Whether the backup completed successfully.
95
	 */
96
	public function verify_backup() {
97
98
		// If there are errors delete the backup file.
99
		if ( $this->get_errors( __CLASS__ ) && file_exists( $this->get_backup_filepath() ) ) {
100
			unlink( $this->get_backup_filepath() );
101
		}
102
103
		// If the backup doesn't exist then we must have failed.
104
		if ( ! file_exists( $this->get_backup_filepath() ) ) {
1 ignored issue
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return file_exists($this->get_backup_filepath());.
Loading history...
105
			return false;
106
		}
107
108
		return true;
109
110
	}
111
112
}
113