CodeSniffer initial steps
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,3 @@ | |||||||
| /vendor/ | /vendor/ | ||||||
| config.yml | config.yml | ||||||
|  | composer.phar | ||||||
| @@ -9,5 +9,8 @@ | |||||||
|         "psr-4": { |         "psr-4": { | ||||||
|             "App\\": "src/" |             "App\\": "src/" | ||||||
|         } |         } | ||||||
|  |     }, | ||||||
|  |     "require-dev": { | ||||||
|  |         "squizlabs/php_codesniffer": "*" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										78
									
								
								composer.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										78
									
								
								composer.lock
									
									
									
										generated
									
									
									
								
							| @@ -4,7 +4,7 @@ | |||||||
|         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||||
|         "This file is @generated automatically" |         "This file is @generated automatically" | ||||||
|     ], |     ], | ||||||
|     "content-hash": "271f743cb0e2ed861cfb8fa7ac075589", |     "content-hash": "d3057be657b112629e5a71cc9d06ebed", | ||||||
|     "packages": [ |     "packages": [ | ||||||
|         { |         { | ||||||
|             "name": "psr/container", |             "name": "psr/container", | ||||||
| @@ -1090,7 +1090,81 @@ | |||||||
|             "time": "2023-05-03T19:06:57+00:00" |             "time": "2023-05-03T19:06:57+00:00" | ||||||
|         } |         } | ||||||
|     ], |     ], | ||||||
|     "packages-dev": [], |     "packages-dev": [ | ||||||
|  |         { | ||||||
|  |             "name": "squizlabs/php_codesniffer", | ||||||
|  |             "version": "2.2.0", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", | ||||||
|  |                 "reference": "b301c98f19414d836fdaa678648745fcca5aeb4f" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b301c98f19414d836fdaa678648745fcca5aeb4f", | ||||||
|  |                 "reference": "b301c98f19414d836fdaa678648745fcca5aeb4f", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "require": { | ||||||
|  |                 "ext-tokenizer": "*", | ||||||
|  |                 "php": ">=5.1.2" | ||||||
|  |             }, | ||||||
|  |             "bin": [ | ||||||
|  |                 "scripts/phpcs", | ||||||
|  |                 "scripts/phpcbf" | ||||||
|  |             ], | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "classmap": [ | ||||||
|  |                     "CodeSniffer.php", | ||||||
|  |                     "CodeSniffer/CLI.php", | ||||||
|  |                     "CodeSniffer/Exception.php", | ||||||
|  |                     "CodeSniffer/File.php", | ||||||
|  |                     "CodeSniffer/Fixer.php", | ||||||
|  |                     "CodeSniffer/Report.php", | ||||||
|  |                     "CodeSniffer/Reporting.php", | ||||||
|  |                     "CodeSniffer/Sniff.php", | ||||||
|  |                     "CodeSniffer/Tokens.php", | ||||||
|  |                     "CodeSniffer/Reports/", | ||||||
|  |                     "CodeSniffer/Tokenizers/", | ||||||
|  |                     "CodeSniffer/DocGenerators/", | ||||||
|  |                     "CodeSniffer/Standards/AbstractPatternSniff.php", | ||||||
|  |                     "CodeSniffer/Standards/AbstractScopeSniff.php", | ||||||
|  |                     "CodeSniffer/Standards/AbstractVariableSniff.php", | ||||||
|  |                     "CodeSniffer/Standards/IncorrectPatternException.php", | ||||||
|  |                     "CodeSniffer/Standards/Generic/Sniffs/", | ||||||
|  |                     "CodeSniffer/Standards/MySource/Sniffs/", | ||||||
|  |                     "CodeSniffer/Standards/PEAR/Sniffs/", | ||||||
|  |                     "CodeSniffer/Standards/PSR1/Sniffs/", | ||||||
|  |                     "CodeSniffer/Standards/PSR2/Sniffs/", | ||||||
|  |                     "CodeSniffer/Standards/Squiz/Sniffs/", | ||||||
|  |                     "CodeSniffer/Standards/Zend/Sniffs/" | ||||||
|  |                 ] | ||||||
|  |             }, | ||||||
|  |             "notification-url": "https://packagist.org/downloads/", | ||||||
|  |             "license": [ | ||||||
|  |                 "BSD-3-Clause" | ||||||
|  |             ], | ||||||
|  |             "authors": [ | ||||||
|  |                 { | ||||||
|  |                     "name": "Greg Sherwood", | ||||||
|  |                     "role": "lead" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", | ||||||
|  |             "homepage": "http://www.squizlabs.com/php-codesniffer", | ||||||
|  |             "keywords": [ | ||||||
|  |                 "phpcs", | ||||||
|  |                 "standards" | ||||||
|  |             ], | ||||||
|  |             "support": { | ||||||
|  |                 "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", | ||||||
|  |                 "source": "https://github.com/squizlabs/PHP_CodeSniffer", | ||||||
|  |                 "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" | ||||||
|  |             }, | ||||||
|  |             "time": "2015-01-21T22:44:05+00:00" | ||||||
|  |         } | ||||||
|  |     ], | ||||||
|     "aliases": [], |     "aliases": [], | ||||||
|     "minimum-stability": "stable", |     "minimum-stability": "stable", | ||||||
|     "stability-flags": [], |     "stability-flags": [], | ||||||
|   | |||||||
| @@ -26,8 +26,8 @@ class CommandBackup extends Command | |||||||
|         $output->writeln('Opening: '.$input->getArgument('config')); |         $output->writeln('Opening: '.$input->getArgument('config')); | ||||||
|         try { |         try { | ||||||
|             $config = Yaml::parseFile($input->getArgument('config')); |             $config = Yaml::parseFile($input->getArgument('config')); | ||||||
|         } catch (ParseException $exception) { |         } catch (ParseException $e) { | ||||||
|             $output->writeln('Unable to parse the YAML string: '. $exception->getMessage()); |             $output->writeln('Unable to parse the YAML string: '. $e->getMessage()); | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         $rclone = new Rclone\Rclone(); |         $rclone = new Rclone\Rclone(); | ||||||
| @@ -38,8 +38,7 @@ class CommandBackup extends Command | |||||||
|         $twig = new \Twig\Environment($loader); |         $twig = new \Twig\Environment($loader); | ||||||
|         $twig->addExtension(new Twig\AppExtension()); |         $twig->addExtension(new Twig\AppExtension()); | ||||||
|  |  | ||||||
|         foreach($config['backup'] as $conf) |         foreach ($config['backup'] as $conf) {    | ||||||
|         {    |  | ||||||
|             try { |             try { | ||||||
|                 $template['config'] = $conf; |                 $template['config'] = $conf; | ||||||
|                 $template['start'] = new \DateTime(); |                 $template['start'] = new \DateTime(); | ||||||
|   | |||||||
| @@ -25,8 +25,8 @@ class CommandShow extends Command | |||||||
|         $output->writeln('Reading from: '.$input->getArgument('config')); |         $output->writeln('Reading from: '.$input->getArgument('config')); | ||||||
|         try { |         try { | ||||||
|             $config = Yaml::parseFile($input->getArgument('config')); |             $config = Yaml::parseFile($input->getArgument('config')); | ||||||
|         } catch (ParseException $exception) { |         } catch (ParseException $e) { | ||||||
|             $output->writeln('Unable to parse the YAML string: '. $exception->getMessage()); |             $output->writeln('Unable to parse the YAML string: '. $e->getMessage()); | ||||||
|         } |         } | ||||||
|         $table = new Table($output); |         $table = new Table($output); | ||||||
|         $table |         $table | ||||||
|   | |||||||
| @@ -1,8 +1,9 @@ | |||||||
| <?php | <?php | ||||||
| namespace App\Ntfy; | namespace App\Ntfy; | ||||||
|  |  | ||||||
| class Ntfy { | class Ntfy | ||||||
|     private $domain; | { | ||||||
|  |     protected $domain; | ||||||
|     function __construct($domain) |     function __construct($domain) | ||||||
|     { |     { | ||||||
|         $this->domain = $domain; |         $this->domain = $domain; | ||||||
| @@ -10,16 +11,18 @@ class Ntfy { | |||||||
|  |  | ||||||
|     function send($topic,$title, $message) |     function send($topic,$title, $message) | ||||||
|     { |     { | ||||||
|         file_get_contents('https://'.$this->domain.'/'.$topic, false, stream_context_create([ |         file_get_contents( | ||||||
|             'http' => [ |             'https://'.$this->domain.'/'.$topic, false, stream_context_create( | ||||||
|  |                 ['http' => [ | ||||||
|                 'method' => 'POST',  |                 'method' => 'POST',  | ||||||
|                 'header' => 'Content-Type: text/plain', |                 'header' => 'Content-Type: text/plain', | ||||||
|                 'header' => |                 'header' => | ||||||
|                     "Content-Type: text/plain\r\n" . |                     "Content-Type: text/plain\r\n" . | ||||||
|                     "Title: $title\r\n", |                     "Title: $title\r\n", | ||||||
|                 'content' => $message |                 'content' => $message] | ||||||
|                 ] |                 ] | ||||||
|         ])); |             ) | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -4,9 +4,10 @@ namespace App\Rclone; | |||||||
| use Symfony\Component\Process\Process; | use Symfony\Component\Process\Process; | ||||||
| use Symfony\Component\Process\Exception\ProcessFailedException; | use Symfony\Component\Process\Exception\ProcessFailedException; | ||||||
|  |  | ||||||
| class Rclone { | class Rclone | ||||||
|     private $rclone_path; | { | ||||||
|     private $global_options = []; |     protected $rclone_path; | ||||||
|  |     protected $global_options = []; | ||||||
|  |  | ||||||
|     function __construct($rclone_path = "rclone") |     function __construct($rclone_path = "rclone") | ||||||
|     { |     { | ||||||
| @@ -31,8 +32,7 @@ class Rclone { | |||||||
|  |  | ||||||
|         $options[] = $src; |         $options[] = $src; | ||||||
|         $options[] = $dest; |         $options[] = $dest; | ||||||
|         if($bandwidth) |         if ($bandwidth) { | ||||||
|         { |  | ||||||
|             $options[] = "--bwlimit"; |             $options[] = "--bwlimit"; | ||||||
|             $options[] = $bandwidth; |             $options[] = $bandwidth; | ||||||
|         } |         } | ||||||
| @@ -40,9 +40,16 @@ class Rclone { | |||||||
|         return $this->exec('copy', $options); |         return $this->exec('copy', $options); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private function exec(string $command, array $options = array()) |     protected function exec(string $command, array $options = array()) | ||||||
|     {    |     {    | ||||||
|         $process = new Process(array_merge([$this->rclone_path], $this->global_options, [$command], $options)); |         $process = new Process( | ||||||
|  |             array_merge( | ||||||
|  |                 [$this->rclone_path], | ||||||
|  |                 $this->global_options, | ||||||
|  |                 [$command], | ||||||
|  |                 $options | ||||||
|  |             ) | ||||||
|  |         ); | ||||||
|         $process->setTimeout(4*3600); |         $process->setTimeout(4*3600); | ||||||
|         $process->run(); |         $process->run(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,15 +16,16 @@ class AppExtension extends AbstractExtension | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param $bytes |      * Format a file size to be human readable | ||||||
|      * @param int $precision |      * @param int $bytes     Number of bytes | ||||||
|      * @return string |      * @param int $precision Precision  | ||||||
|  |      * @return string Formatted string | ||||||
|      */ |      */ | ||||||
|     public function formatBytes($bytes, $precision = 2) |     public function formatBytes($bytes, $precision = 2) | ||||||
|     { |     { | ||||||
|         $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; |         $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; | ||||||
|         $factor = floor((strlen($bytes) - 1) / 3); |         $fact = floor((strlen($bytes) - 1) / 3); | ||||||
|         return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . @$size[$factor]; |         return sprintf("%.{$precision}f", $bytes / pow(1024, $fact)) . $size[$fact]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user