Skip to content

Commit

Permalink
coding style: fixes in code
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 12, 2017
1 parent 976f1d8 commit 6595212
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 132 deletions.
10 changes: 5 additions & 5 deletions src/Deployment/CliRunner.php
Expand Up @@ -28,7 +28,7 @@ class CliRunner
];

/** @var string[] */
public $ignoreMasks = ['*.bak', '.svn' , '.git*', 'Thumbs.db', '.DS_Store', '.idea'];
public $ignoreMasks = ['*.bak', '.svn', '.git*', 'Thumbs.db', '.DS_Store', '.idea'];

/** @var Logger */
private $logger;
Expand Down Expand Up @@ -67,7 +67,7 @@ public function run()
}

$time = time();
$this->logger->log("Started at " . date('[Y/m/d H:i]'));
$this->logger->log('Started at ' . date('[Y/m/d H:i]'));
$this->logger->log("Config file is $this->configFile");

foreach ($this->batches as $name => $batch) {
Expand All @@ -79,7 +79,7 @@ public function run()
if ($this->mode === 'generate') {
$this->logger->log('Scanning files');
$localPaths = $deployment->collectPaths();
$this->logger->log("Saved " . $deployment->writeDeploymentFile($localPaths));
$this->logger->log('Saved ' . $deployment->writeDeploymentFile($localPaths));
continue;
}

Expand Down Expand Up @@ -171,7 +171,7 @@ private function setupPhp()
/** @return array */
private function loadConfig()
{
$cmd = new CommandLine(<<<XX
$cmd = new CommandLine(<<<'XX'
FTP deployment v2.7
-------------------
Expand Down Expand Up @@ -210,7 +210,7 @@ private function loadConfig()
? ['' => $config]
: array_filter($config, 'is_array');

foreach ($this->batches as & $batch) {
foreach ($this->batches as &$batch) {
$batch = array_change_key_case($batch, CASE_LOWER) + $this->defaults;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Deployment/CommandLine.php
Expand Up @@ -146,7 +146,7 @@ public function help()
}


public function checkArg(array $opt, & $arg)
public function checkArg(array $opt, &$arg)
{
if (!empty($opt[self::REALPATH])) {
$path = realpath($arg);
Expand Down
12 changes: 6 additions & 6 deletions src/Deployment/Deployer.php
Expand Up @@ -43,6 +43,9 @@ class Deployer
/** @var string */
public $tempDir = '';

/** @var string[] */
public $preprocessMasks = [];

/** @var string */
private $localDir;

Expand All @@ -52,9 +55,6 @@ class Deployer
/** @var Logger */
private $logger;

/** @var string[] */
public $preprocessMasks = [];

/** @var array */
private $filters = [];

Expand Down Expand Up @@ -83,7 +83,7 @@ public function __construct(Server $server, $localDir, Logger $logger)
*/
public function deploy()
{
$this->logger->log("Connecting to server");
$this->logger->log('Connecting to server');
$this->server->connect();
$this->remoteDir = $this->server->getDir();

Expand Down Expand Up @@ -321,7 +321,7 @@ public function collectPaths($subdir = '')
$list = [];
$iterator = dir($this->localDir . $subdir);
$counter = 0;
while (false !== ($entry = $iterator->read())) {
while (($entry = $iterator->read()) !== false) {
$this->logger->progress(str_pad(str_repeat('.', $counter++ % 40), 40));

$path = "$this->localDir$subdir/$entry";
Expand Down Expand Up @@ -436,7 +436,7 @@ private function writeProgress($count, $total, $path, $percent = null, $color =
if ($percent === null) {
$this->logger->log($s, $color);
} else {
$this->logger->progress($s . ' [' . round($percent) . "%]");
$this->logger->progress($s . ' [' . round($percent) . '%]');
}
}
}
6 changes: 3 additions & 3 deletions src/Deployment/FtpServer.php
Expand Up @@ -44,7 +44,7 @@ public function __construct($url, $passiveMode = true)
}
$this->url = $url = is_array($url) ? $url : parse_url($url);
if (!isset($url['scheme'], $url['user'], $url['pass']) || ($url['scheme'] !== 'ftp' && $url['scheme'] !== 'ftps')) {
throw new \InvalidArgumentException("Invalid URL or missing username or password");
throw new \InvalidArgumentException('Invalid URL or missing username or password');
} elseif ($url['scheme'] === 'ftps' && !function_exists('ftp_ssl_connect')) {
throw new \Exception('PHP extension OpenSSL is not built statically in PHP.');
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public function removeFile($file)
try {
$this->ftp('delete', $file);
} catch (FtpException $e) {
if (in_array($file, (array) $this->ftp('nlist', $file . '*'))) {
if (in_array($file, (array) $this->ftp('nlist', $file . '*'), true)) {
throw $e;
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public function removeDir($dir)
try {
$this->ftp('rmDir', $dir);
} catch (FtpException $e) {
if (in_array($dir, (array) $this->ftp('nlist', $dir . '*'))) {
if (in_array($dir, (array) $this->ftp('nlist', $dir . '*'), true)) {
throw $e;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Deployment/Helpers.php
Expand Up @@ -80,7 +80,7 @@ public static function matchMask($path, array $patterns, $isDir = false)
* Processes HTTP request.
* @return string
*/
public static function fetchUrl($url, & $error, array $postData = null)
public static function fetchUrl($url, &$error, array $postData = null)
{
if (extension_loaded('curl')) {
$ch = curl_init($url);
Expand All @@ -106,7 +106,7 @@ public static function fetchUrl($url, & $error, array $postData = null)
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($postData, null, '&'),
]
],
]));
$error = $output === false
? preg_replace("#^file_get_contents\(.*?\): #", '', error_get_last()['message'])
Expand Down
6 changes: 3 additions & 3 deletions src/Deployment/Logger.php
Expand Up @@ -14,15 +14,15 @@
*/
class Logger
{
/** @var resource */
private $file;

/** @var bool */
public $useColors;

/** @var bool */
public $showProgress = true;

/** @var resource */
private $file;

/** @var array */
private $colors = [
'black' => '0;30',
Expand Down
10 changes: 5 additions & 5 deletions src/Deployment/SshServer.php
Expand Up @@ -14,15 +14,15 @@
*/
class SshServer implements Server
{
/** @var resource */
private $connection;

/** @var int */
public $filePermissions;

/** @var int */
public $dirPermissions;

/** @var resource */
private $connection;

/** @var resource */
private $sftp;

Expand All @@ -41,7 +41,7 @@ public function __construct($url)
}
$this->url = is_array($url) ? $url : parse_url($url);
if (!isset($this->url['scheme'], $this->url['user']) || $this->url['scheme'] !== 'sftp') {
throw new \InvalidArgumentException("Invalid URL or missing username");
throw new \InvalidArgumentException('Invalid URL or missing username');
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public function purge($dir, callable $progress = null)
$dirs = $entries = [];

$iterator = dir($path = "ssh2.sftp://$this->sftp$dir");
while (false !== ($entry = $iterator->read())) {
while (($entry = $iterator->read()) !== false) {
if ($entry !== '.' && $entry !== '..') {
$entries[] = $entry;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Helpers.hashFile.phpt
Expand Up @@ -7,7 +7,7 @@ require __DIR__ . '/bootstrap.php';


file_put_contents(TEMP_DIR . '/file', "a\r\nb");
Assert::same( md5("a\nb"), Helpers::hashFile(TEMP_DIR . '/file') );
Assert::same(md5("a\nb"), Helpers::hashFile(TEMP_DIR . '/file'));

file_put_contents(TEMP_DIR . '/file', "a\r\nb\x00");
Assert::same( md5("a\r\nb\x00"), Helpers::hashFile(TEMP_DIR . '/file') );
Assert::same(md5("a\r\nb\x00"), Helpers::hashFile(TEMP_DIR . '/file'));

0 comments on commit 6595212

Please sign in to comment.