Skip to content

Commit

Permalink
Merge pull request #82 from jolicode/php-cs-fixer
Browse files Browse the repository at this point in the history
Update php-cs-fixer and its config and fix the codebase
  • Loading branch information
pyrech committed Dec 1, 2021
2 parents a15bfc0 + 50169f7 commit 535d9ed
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 128 deletions.
55 changes: 28 additions & 27 deletions .php-cs-fixer.php
@@ -1,6 +1,15 @@
<?php

$header = <<<'EOF'
/*
* This file is part of the JoliNotif project.
*
* (c) Loïck Piera <pyrech@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$fileHeaderComment = <<<'EOF'
This file is part of the JoliNotif project.
(c) Loïck Piera <pyrech@gmail.com>
Expand All @@ -9,33 +18,25 @@
file that was distributed with this source code.
EOF;

$config = new PhpCsFixer\Config();
$config
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->append([
__FILE__,
])
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules(array(
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'header_comment' => array('header' => $header),
'array_syntax' => array('syntax' => 'short'),
'ordered_class_elements' => true,
'ordered_imports' => true,
'heredoc_to_nowdoc' => true,
'php_unit_strict' => true,
'php_unit_construct' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'strict_comparison' => true,
'strict_param' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'semicolon_after_instruction' => true,
'combine_consecutive_unsets' => true,
))
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
)
'@PHP71Migration' => true,
'@PhpCsFixer' => true,
'php_unit_internal_class' => false, // From @PhpCsFixer but we don't want it
'php_unit_test_class_requires_covers' => false, // From @PhpCsFixer but we don't want it
'phpdoc_add_missing_param_annotation' => false, // From @PhpCsFixer but we don't want it
'header_comment' => ['header' => $fileHeaderComment],
'concat_space' => ['spacing' => 'one'],
])
->setFinder($finder)
;

return $config;
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -25,7 +25,7 @@
"symfony/process": "^4.0|^5.0|^6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.3.2",
"symfony/finder": "^5.0",
"symfony/phpunit-bridge": "^5.0"
},
Expand Down
8 changes: 4 additions & 4 deletions example/index.php
Expand Up @@ -13,16 +13,16 @@
use Joli\JoliNotif\Notifier\NullNotifier;
use Joli\JoliNotif\NotifierFactory;

require __DIR__.'/../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

$notifier = NotifierFactory::create();

if (!($notifier instanceof NullNotifier)) {
$notification =
(new Notification())
->setTitle('Notification example')
->setBody('This is a notification example. Pretty cool isn\'t it?')
->setIcon(__DIR__.'/icon-success.png')
->setTitle('Notification example')
->setBody('This is a notification example. Pretty cool isn\'t it?')
->setIcon(__DIR__ . '/icon-success.png')
;

$result = $notifier->send($notification);
Expand Down
14 changes: 7 additions & 7 deletions src/Notification.php
Expand Up @@ -17,17 +17,17 @@
class Notification
{
/**
* @var string|null
* @var null|string
*/
private $title;

/**
* @var string|null
* @var null|string
*/
private $body;

/**
* @var string|null
* @var null|string
*/
private $icon;

Expand All @@ -37,7 +37,7 @@ class Notification
private $options = [];

/**
* @return string|null
* @return null|string
*/
public function getTitle()
{
Expand All @@ -52,7 +52,7 @@ public function setTitle(string $title): self
}

/**
* @return string|null
* @return null|string
*/
public function getBody()
{
Expand All @@ -67,7 +67,7 @@ public function setBody(string $body): self
}

/**
* @return string|null
* @return null|string
*/
public function getIcon()
{
Expand All @@ -92,7 +92,7 @@ public function setIcon(string $icon): self
}

/**
* @return string|null
* @return null|string
*/
public function getOption(string $key)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Notifier/AppleScriptNotifier.php
Expand Up @@ -52,18 +52,18 @@ public function getPriority(): int
*/
protected function getCommandLineArguments(Notification $notification): array
{
$script = 'display notification "'.str_replace('"', '\\"', $notification->getBody()).'"';
$script = 'display notification "' . str_replace('"', '\\"', $notification->getBody()) . '"';

if ($notification->getTitle()) {
$script .= ' with title "'.str_replace('"', '\\"', $notification->getTitle()).'"';
$script .= ' with title "' . str_replace('"', '\\"', $notification->getTitle()) . '"';
}

if ($notification->getOption('subtitle')) {
$script .= ' subtitle "'.str_replace('"', '\\"', $notification->getOption('subtitle')).'"';
$script .= ' subtitle "' . str_replace('"', '\\"', $notification->getOption('subtitle')) . '"';
}

if ($notification->getOption('sound')) {
$script .= ' sound name "'.str_replace('"', '\\"', $notification->getOption('sound')).'"';
$script .= ' sound name "' . str_replace('"', '\\"', $notification->getOption('sound')) . '"';
}

return [
Expand Down
6 changes: 3 additions & 3 deletions src/Notifier/CliBasedNotifier.php
Expand Up @@ -68,14 +68,14 @@ public function send(Notification $notification): bool
$arguments = $this->getCommandLineArguments($notification);

if (self::SUPPORT_BINARY_PROVIDED === $this->support && $this instanceof BinaryProvider) {
$dir = rtrim($this->getRootDir(), '/').'/';
$embeddedBinary = $dir.$this->getEmbeddedBinary();
$dir = rtrim($this->getRootDir(), '/') . '/';
$embeddedBinary = $dir . $this->getEmbeddedBinary();

if (PharExtractor::isLocatedInsideAPhar($embeddedBinary)) {
$embeddedBinary = PharExtractor::extractFile($embeddedBinary);

foreach ($this->getExtraFiles() as $file) {
PharExtractor::extractFile($dir.$file);
PharExtractor::extractFile($dir . $file);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Notifier/NotifuNotifier.php
Expand Up @@ -49,7 +49,7 @@ public function canBeUsed(): bool
*/
public function getRootDir(): string
{
return \dirname(__DIR__, 2).'/bin/notifu';
return \dirname(__DIR__, 2) . '/bin/notifu';
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Notifier/SnoreToastNotifier.php
Expand Up @@ -44,8 +44,7 @@ public function canBeUsed(): bool
{
return
(OsHelper::isWindows() && OsHelper::isWindowsEightOrHigher())
||
OsHelper::isWindowsSubsystemForLinux()
|| OsHelper::isWindowsSubsystemForLinux()
;
}

Expand All @@ -54,7 +53,7 @@ public function canBeUsed(): bool
*/
public function getRootDir(): string
{
return \dirname(__DIR__, 2).'/bin/snoreToast';
return \dirname(__DIR__, 2) . '/bin/snoreToast';
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Notifier/ToasterNotifier.php
Expand Up @@ -45,8 +45,7 @@ public function canBeUsed(): bool
{
return
(OsHelper::isWindows() && OsHelper::isWindowsEightOrHigher())
||
OsHelper::isWindowsSubsystemForLinux()
|| OsHelper::isWindowsSubsystemForLinux()
;
}

Expand All @@ -55,7 +54,7 @@ public function canBeUsed(): bool
*/
public function getRootDir(): string
{
return \dirname(__DIR__, 2).'/bin/toaster';
return \dirname(__DIR__, 2) . '/bin/toaster';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/NotifierFactory.php
Expand Up @@ -102,11 +102,11 @@ private static function getWindowsNotifiers(): array
/**
* @param Notifier[] $notifiers
*
* @return Notifier|null
* @return null|Notifier
*/
private static function chooseBestNotifier(array $notifiers)
{
/** @var Notifier|null $bestNotifier */
/** @var null|Notifier $bestNotifier */
$bestNotifier = null;

foreach ($notifiers as $notifier) {
Expand Down
4 changes: 2 additions & 2 deletions src/Util/PharExtractor.php
Expand Up @@ -35,8 +35,8 @@ public static function extractFile(string $filePath, bool $overwrite = false): s
}

$relativeFilePath = substr($filePath, strpos($filePath, $pharPath) + \strlen($pharPath) + 1);
$tmpDir = sys_get_temp_dir().'/jolinotif';
$extractedFilePath = $tmpDir.'/'.$relativeFilePath;
$tmpDir = sys_get_temp_dir() . '/jolinotif';
$extractedFilePath = $tmpDir . '/' . $relativeFilePath;

if (!file_exists($extractedFilePath) || $overwrite) {
$phar = new \Phar($pharPath);
Expand Down
20 changes: 10 additions & 10 deletions tests/NotificationTest.php
Expand Up @@ -22,10 +22,10 @@ public function testItExtractsIconFromPhar()
$key = uniqid('', true);
$iconContent = $key;
$rootPackage = \dirname(__DIR__);
$iconRelativePath = 'Resources/notification/icon-'.$key.'.png';
$testDir = sys_get_temp_dir().'/test-jolinotif';
$pharPath = $testDir.'/notification-extract-icon-'.$key.'.phar';
$extractedIconPath = sys_get_temp_dir().'/jolinotif/'.$iconRelativePath;
$iconRelativePath = 'Resources/notification/icon-' . $key . '.png';
$testDir = sys_get_temp_dir() . '/test-jolinotif';
$pharPath = $testDir . '/notification-extract-icon-' . $key . '.phar';
$extractedIconPath = sys_get_temp_dir() . '/jolinotif/' . $iconRelativePath;

if (!is_dir($testDir)) {
mkdir($testDir);
Expand All @@ -43,9 +43,9 @@ public function testItExtractsIconFromPhar()
PHAR_BOOTSTRAP;

$files = (new Finder())
->in("$rootPackage/src")
->in("$rootPackage/tests/fixtures")
->in("$rootPackage/vendor")
->in("{$rootPackage}/src")
->in("{$rootPackage}/tests/fixtures")
->in("{$rootPackage}/vendor")
->notPath('vendor/symfony/phpunit-bridge/bin/simple-phpunit')
->files()
;
Expand All @@ -62,7 +62,7 @@ public function testItExtractsIconFromPhar()

$this->assertFileExists($pharPath);

exec('php '.$pharPath);
exec('php ' . $pharPath);

$this->assertFileExists($extractedIconPath);
$this->assertSame($iconContent, file_get_contents($extractedIconPath));
Expand All @@ -71,8 +71,8 @@ public function testItExtractsIconFromPhar()
public function testItResolvesRealPathToIcon()
{
$notification = new Notification();
$notification->setIcon(__DIR__.'/../tests/fixtures/image.gif');
$notification->setIcon(__DIR__ . '/../tests/fixtures/image.gif');

$this->assertFileEquals(__DIR__.'/fixtures/image.gif', $notification->getIcon());
$this->assertFileEquals(__DIR__ . '/fixtures/image.gif', $notification->getIcon());
}
}
12 changes: 6 additions & 6 deletions tests/Notifier/AppleScriptNotifierTest.php
Expand Up @@ -56,7 +56,7 @@ protected function getNotifier(): Notifier
*/
protected function getExpectedCommandLineForNotification(): string
{
return <<<CLI
return <<<'CLI'
'osascript' '-e' 'display notification "I'\''m the notification body"'
CLI;
}
Expand All @@ -66,7 +66,7 @@ protected function getExpectedCommandLineForNotification(): string
*/
protected function getExpectedCommandLineForNotificationWithATitle(): string
{
return <<<CLI
return <<<'CLI'
'osascript' '-e' 'display notification "I'\''m the notification body" with title "I'\''m the notification title"'
CLI;
}
Expand All @@ -76,7 +76,7 @@ protected function getExpectedCommandLineForNotificationWithATitle(): string
*/
protected function getExpectedCommandLineForNotificationWithASubtitle(): string
{
return <<<CLI
return <<<'CLI'
'osascript' '-e' 'display notification "I'\''m the notification body" subtitle "I'\''m the notification subtitle"'
CLI;
}
Expand All @@ -86,7 +86,7 @@ protected function getExpectedCommandLineForNotificationWithASubtitle(): string
*/
protected function getExpectedCommandLineForNotificationWithASound(): string
{
return <<<CLI
return <<<'CLI'
'osascript' '-e' 'display notification "I'\''m the notification body" sound name "Frog"'
CLI;
}
Expand All @@ -96,7 +96,7 @@ protected function getExpectedCommandLineForNotificationWithASound(): string
*/
protected function getExpectedCommandLineForNotificationWithAnIcon(): string
{
return <<<CLI
return <<<'CLI'
'osascript' '-e' 'display notification "I'\''m the notification body"'
CLI;
}
Expand All @@ -106,7 +106,7 @@ protected function getExpectedCommandLineForNotificationWithAnIcon(): string
*/
protected function getExpectedCommandLineForNotificationWithAllOptions(): string
{
return <<<CLI
return <<<'CLI'
'osascript' '-e' 'display notification "I'\''m the notification body" with title "I'\''m the notification title" subtitle "I'\''m the notification subtitle" sound name "Frog"'
CLI;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Notifier/BinaryProviderTestTrait.php
Expand Up @@ -27,7 +27,7 @@ public function testEmbeddedBinaryExists()
{
$notifier = $this->getNotifier();

$this->assertFileExists($notifier->getRootDir().\DIRECTORY_SEPARATOR.$notifier->getEmbeddedBinary());
$this->assertFileExists($notifier->getRootDir() . \DIRECTORY_SEPARATOR . $notifier->getEmbeddedBinary());
}

public function testExtraFilesExist()
Expand All @@ -42,7 +42,7 @@ public function testExtraFilesExist()
}

foreach ($notifier->getExtraFiles() as $file) {
$this->assertFileExists($notifier->getRootDir().\DIRECTORY_SEPARATOR.$file);
$this->assertFileExists($notifier->getRootDir() . \DIRECTORY_SEPARATOR . $file);
}
}
}

0 comments on commit 535d9ed

Please sign in to comment.