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 (#1054)
by Tom
02:18
created

Zip_Archive_File_Backup_Engine   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 10
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
D backup() 0 40 9
1
<?php
2
3
namespace HM\BackUpWordPress;
4
5
/**
6
 * Perform a file backup using the native PHP ZipArchive extension
7
 */
8
class Zip_Archive_File_Backup_Engine extends File_Backup_Engine {
9
10
	public function __construct() {
11
		parent::__construct();
12
	}
13
14
	public function backup() {
15
16
		if ( ! class_exists( 'ZipArchive' ) ) {
17
			return false;
18
		}
19
20
		$zip = new \ZipArchive();
21
22
		// Attempt to create the zip file.
23
		if ( $zip->open( $this->get_backup_filepath(), \ZIPARCHIVE::CREATE ) ) {
24
25
			foreach ( $this->get_files() as $file ) {
26
27
				// Create an empty directory for each directory in the filesystem
28
				if ( $file->isDir() ) {
29
					$zip->addEmptyDir( $file->getRelativePathname() );
30
				} elseif ( $file->isFile() ) { // Archive the file with a relative path
31
					$zip->addFile( $file->getPathname(), $file->getRelativePathname() );
32
				}
33
			}
34
35
			// Track any internal warnings
36
			if ( $zip->status ) {
37
				$this->warning( __CLASS__, $zip->status );
38
			}
39
40
			// @codingStandardsIgnoreStart
41
			if ( $zip->statusSys ) {
42
				$this->warning( __CLASS__, $zip->statusSys );
43
			}
44
			// @codingStandardsIgnoreEnd
45
46
			if ( file_exists( $this->get_backup_filepath() ) ) {
47
				$zip->close();
48
			}
49
		}
50
51
		return $this->verify_backup();
52
53
	}
54
}
55