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:44
created

IMysqldump_Database_Backup_Engine::get_dsn()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 7
nc 3
nop 0
1
<?php
2
3
namespace HM\BackUpWordPress;
4
5
use Ifsnop\Mysqldump as IMysqldump;
6
7
/**
8
 * Perform a database backup using the mysqldump-php library
9
 *
10
 * @see https://github.com/ifsnop/mysqldump-php
11
 */
12
class IMysqldump_Database_Backup_Engine extends Database_Backup_Engine {
13
14
	public function __construct() {
15
		parent::__construct();
16
	}
17
18
	/**
19
	 * Perform the database backupwordpress
20
	 *
21
	 * @return bool True if the backup completed successfully, else false.
22
	 */
23
	public function backup() {
24
25
		try {
26
27
			$dump = new IMysqldump\Mysqldump( $this->get_dsn(), $this->get_user(), $this->get_password(), $this->get_dump_settings() );
28
			$dump->start( $this->get_backup_filepath() );
29
30
		} catch ( \Exception $e ) {
31
			$this->error( __CLASS__, $e->getMessage() );
32
		}
33
34
		return $this->verify_backup();
35
36
	}
37
38
	/**
39
	 * Get the settings for the database bump.
40
	 *
41
	 * @return array The array of database dump settings.
42
	 */
43
	public function get_dump_settings() {
44
45
		/**
46
		 * Allow additional settings to be added.
47
		 *
48
		 * @param string[] $settings The array of settings.
49
		 * @todo can these be standardised across all database backup engines
50
		 */
51
		return apply_filters( 'hmbkp_imysqldump_command', array(
52
			'default-character-set' => $this->get_charset(),
53
			'hex-blob'              => true,
54
			'single-transaction'    => defined( 'HMBKP_MYSQLDUMP_SINGLE_TRANSACTION' ) && HMBKP_MYSQLDUMP_SINGLE_TRANSACTION
55
		) );
56
57
	}
58
59
	/**
60
	 * Correctly calculates the DSN string for the various mysql
61
	 * connection variations including simplt hostname, non-standard ports
62
	 * and socket connections.
63
	 *
64
	 * @return string  The DSN connection string
65
	 */
66
	public function get_dsn() {
67
68
		$dsn = 'mysql:host=' . $this->get_host() . ';dbname=' . $this->get_name();
69
70
		if ( $this->get_host() && $this->get_port() ) {
71
			$dsn = 'mysql:host=' . $this->get_host() . ';port=' . $this->get_port() . ';dbname=' . $this->get_name();
72
		}
73
74
		elseif ( $this->get_socket() ) {
75
			$dsn = 'mysql:unix_socket=' . $this->get_socket() . ';dbname=' . $this->get_name();
76
		}
77
78
		return $dsn;
79
80
	}
81
82
}
83