Skip to content

Commit cd4ec9f

Browse files
committed
use php-cs-fixer
1 parent 178e31c commit cd4ec9f

File tree

8 files changed

+196
-129
lines changed

8 files changed

+196
-129
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.php_cs.cache

.php_cs.dist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
$header = <<<'HEADER'
4+
This file is part of the alfred-github-workflow package.
5+
6+
(c) Gregor Harlan
7+
8+
For the full copyright and license information, please view the LICENSE
9+
file that was distributed with this source code.
10+
HEADER;
11+
12+
return PhpCsFixer\Config::create()
13+
->setRiskyAllowed(true)
14+
->setRules([
15+
'@Symfony' => true,
16+
'@Symfony:risky' => true,
17+
'array_syntax' => ['syntax' => 'long'],
18+
'blank_line_before_return' => false,
19+
'combine_consecutive_unsets' => true,
20+
'header_comment' => ['header' => $header],
21+
'method_argument_space' => false,
22+
'no_useless_else' => true,
23+
])
24+
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__))
25+
;

action.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
<?php
22

3+
/*
4+
* This file is part of the alfred-github-workflow package.
5+
*
6+
* (c) Gregor Harlan
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
require 'workflow.php';
413

514
$query = trim($argv[1]);
615

716
if ('>' !== $query[0] && 0 !== strpos($query, 'e >')) {
817
if ('.git' == substr($query, -4)) {
9-
$query = 'github-mac://openRepo/' . substr($query, 0, -4);
18+
$query = 'github-mac://openRepo/'.substr($query, 0, -4);
1019
}
11-
exec('osascript -e "open location \"' . $query . '\""');
20+
exec('osascript -e "open location \"'.$query.'\""');
1221
return;
1322
}
1423

@@ -39,8 +48,8 @@
3948
} elseif (!$enterprise) {
4049
Workflow::startServer();
4150
$state = version_compare(PHP_VERSION, '5.4', '<') ? 'm' : '';
42-
$url = Workflow::getBaseUrl() . '/login/oauth/authorize?client_id=2d4f43826cb68e11c17c&scope=repo&state=' . $state;
43-
exec('open ' . escapeshellarg($url));
51+
$url = Workflow::getBaseUrl().'/login/oauth/authorize?client_id=2d4f43826cb68e11c17c&scope=repo&state='.$state;
52+
exec('open '.escapeshellarg($url));
4453
}
4554
break;
4655

bin/create_icons.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
),
4444
);
4545

46-
$dir = __DIR__ . '/../icons/';
46+
$dir = __DIR__.'/../icons/';
4747

4848
$baseImg = new Imagick();
4949
$baseImg->newImage(256, 256, new ImagickPixel('transparent'));
@@ -63,8 +63,8 @@
6363
foreach ($set as $char => $name) {
6464
$img = clone $baseImg;
6565
$img->annotateImage($draw, 0, 0, 0, json_decode('"\u'.$char.'"'));
66-
$img->writeImage($dir . $name . '.png');
66+
$img->writeImage($dir.$name.'.png');
6767
}
6868
}
6969

70-
rename($dir . 'github.png', __DIR__ . '/../icon.png');
70+
rename($dir.'github.png', __DIR__.'/../icon.png');

curl.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the alfred-github-workflow package.
5+
*
6+
* (c) Gregor Harlan
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
class Curl
413
{
514
/** @var CurlRequest[] */
@@ -56,7 +65,7 @@ public function execute()
5665
'link' => 'Link',
5766
);
5867
foreach ($headerNames as $key => $name) {
59-
$response->$key = Curl::getHeader($header, $name);
68+
$response->$key = self::getHeader($header, $name);
6069
}
6170
if (200 == $response->status) {
6271
$response->content = $body;
@@ -97,12 +106,12 @@ private function addHandle(CurlRequest $request)
97106
$options = $defaultOptions;
98107
$options[CURLOPT_URL] = $request->url;
99108
$header = array();
100-
$header[] = 'X-Url: ' . $request->url;
109+
$header[] = 'X-Url: '.$request->url;
101110
if ($request->token) {
102-
$header[] = 'Authorization: token ' . $request->token;
111+
$header[] = 'Authorization: token '.$request->token;
103112
}
104113
if ($request->etag) {
105-
$header[] = 'If-None-Match: ' . $request->etag;
114+
$header[] = 'If-None-Match: '.$request->etag;
106115
}
107116
$options[CURLOPT_HTTPHEADER] = $header;
108117
curl_setopt_array($ch, $options);
@@ -111,7 +120,7 @@ private function addHandle(CurlRequest $request)
111120

112121
public static function getHeader($header, $key)
113122
{
114-
if (preg_match('/^' . preg_quote($key, '/') . ': (\V*)/mi', $header, $match)) {
123+
if (preg_match('/^'.preg_quote($key, '/').': (\V*)/mi', $header, $match)) {
115124
return $match[1];
116125
}
117126
return null;

item.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the alfred-github-workflow package.
5+
*
6+
* (c) Gregor Harlan
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
class Item
413
{
514
private $randomUid = false;
@@ -19,7 +28,7 @@ class Item
1928

2029
public static function create()
2130
{
22-
return new self;
31+
return new self();
2332
}
2433

2534
public function randomUid()
@@ -99,7 +108,7 @@ public function match($query)
99108
return false;
100109
}
101110
if ($i === $k) {
102-
$this->sameChars++;
111+
++$this->sameChars;
103112
}
104113
}
105114
$this->missingChars = strlen($comparator) - $queryLength;
@@ -119,6 +128,7 @@ public function compare(self $another)
119128

120129
/**
121130
* @param self[] $items
131+
*
122132
* @return string
123133
*/
124134
public static function toXml(array $items, $enterprise, $hotkey, $baseUrl)
@@ -127,19 +137,19 @@ public static function toXml(array $items, $enterprise, $hotkey, $baseUrl)
127137
$prefix = $hotkey ? '' : ' ';
128138
foreach ($items as $item) {
129139
$c = $xml->addChild('item');
130-
$title = $item->prefix . $item->title;
131-
$c->addAttribute('uid', $item->randomUid ? md5(time() . $title) : md5($title));
132-
if ($item->icon && file_exists(__DIR__ . '/icons/' . $item->icon . '.png')) {
133-
$c->addChild('icon', 'icons/' . $item->icon . '.png');
140+
$title = $item->prefix.$item->title;
141+
$c->addAttribute('uid', $item->randomUid ? md5(time().$title) : md5($title));
142+
if ($item->icon && file_exists(__DIR__.'/icons/'.$item->icon.'.png')) {
143+
$c->addChild('icon', 'icons/'.$item->icon.'.png');
134144
} else {
135145
$c->addChild('icon', 'icon.png');
136146
}
137147
if ($item->arg) {
138148
$arg = $item->arg;
139149
if ('/' === $arg[0]) {
140-
$arg = $baseUrl . $arg;
150+
$arg = $baseUrl.$arg;
141151
} elseif (false === strpos($arg, '://')) {
142-
$arg = ($enterprise ? 'e ' : '') . $arg;
152+
$arg = ($enterprise ? 'e ' : '').$arg;
143153
}
144154
$c->addAttribute('arg', $arg);
145155
}
@@ -151,7 +161,7 @@ public static function toXml(array $items, $enterprise, $hotkey, $baseUrl)
151161
} else {
152162
$autocomplete = $item->title;
153163
}
154-
$c->addAttribute('autocomplete', $prefix . ($item->prefixOnlyTitle ? $autocomplete : $item->prefix . $autocomplete));
164+
$c->addAttribute('autocomplete', $prefix.($item->prefixOnlyTitle ? $autocomplete : $item->prefix.$autocomplete));
155165
}
156166
if (!$item->valid) {
157167
$c->addAttribute('valid', 'no');

0 commit comments

Comments
 (0)