hhxsv5 /
laravel-s
| 1 | <?php |
||||||
| 2 | |||||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||||
| 3 | namespace Hhxsv5\LaravelS\Swoole; |
||||||
| 4 | |||||||
| 5 | use Hhxsv5\LaravelS\Console\Portal; |
||||||
| 6 | use Swoole\Http\Server; |
||||||
|
0 ignored issues
–
show
This use statement conflicts with another class in this namespace,
Hhxsv5\LaravelS\Swoole\Server. Consider defining an alias.
Let?s assume that you have a directory layout like this: .
|-- OtherDir
| |-- Bar.php
| `-- Foo.php
`-- SomeDir
`-- Foo.php
and let?s assume the following content of // Bar.php
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // Bar.php
namespace OtherDir;
use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
|
|||||||
| 7 | use Swoole\Process; |
||||||
| 8 | |||||||
| 9 | trait InotifyTrait |
||||||
|
0 ignored issues
–
show
|
|||||||
| 10 | { |
||||||
| 11 | public function addInotifyProcess(Server $swoole, array $config, array $laravelConf) |
||||||
|
0 ignored issues
–
show
|
|||||||
| 12 | { |
||||||
| 13 | if (empty($config['enable'])) { |
||||||
| 14 | return false; |
||||||
| 15 | } |
||||||
| 16 | |||||||
| 17 | if (!extension_loaded('inotify')) { |
||||||
| 18 | $this->warning('Require extension inotify'); |
||||||
|
0 ignored issues
–
show
It seems like
warning() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 19 | return false; |
||||||
| 20 | } |
||||||
| 21 | |||||||
| 22 | $fileTypes = isset($config['file_types']) ? (array)$config['file_types'] : []; |
||||||
| 23 | if (empty($fileTypes)) { |
||||||
| 24 | $this->warning('No file types to watch by inotify'); |
||||||
| 25 | return false; |
||||||
| 26 | } |
||||||
| 27 | |||||||
| 28 | $callback = function () use ($config, $laravelConf) { |
||||||
| 29 | $log = !empty($config['log']); |
||||||
| 30 | $this->setProcessTitle(sprintf('%s laravels: inotify process', $config['process_prefix'])); |
||||||
|
0 ignored issues
–
show
It seems like
setProcessTitle() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 31 | $inotify = new Inotify($config['watch_path'], IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVE, |
||||||
|
0 ignored issues
–
show
|
|||||||
| 32 | function ($event) use ($log, $laravelConf) { |
||||||
| 33 | Portal::runLaravelSCommand($laravelConf['root_path'], 'reload'); |
||||||
| 34 | if ($log) { |
||||||
| 35 | $action = 'file:'; |
||||||
| 36 | switch ($event['mask']) { |
||||||
| 37 | case IN_CREATE: |
||||||
|
0 ignored issues
–
show
|
|||||||
| 38 | $action = 'create'; |
||||||
| 39 | break; |
||||||
| 40 | case IN_DELETE: |
||||||
|
0 ignored issues
–
show
|
|||||||
| 41 | $action = 'delete'; |
||||||
| 42 | break; |
||||||
| 43 | case IN_MODIFY: |
||||||
|
0 ignored issues
–
show
|
|||||||
| 44 | $action = 'modify'; |
||||||
| 45 | break; |
||||||
| 46 | case IN_MOVE: |
||||||
|
0 ignored issues
–
show
|
|||||||
| 47 | $action = 'move'; |
||||||
| 48 | break; |
||||||
| 49 | } |
||||||
| 50 | $this->info(sprintf('reloaded by inotify, reason: %s %s', $action, $event['name'])); |
||||||
|
0 ignored issues
–
show
It seems like
info() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 51 | } |
||||||
| 52 | }); |
||||||
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||||||
| 53 | $inotify->addFileTypes($config['file_types']); |
||||||
| 54 | if (empty($config['excluded_dirs'])) { |
||||||
| 55 | $config['excluded_dirs'] = []; |
||||||
| 56 | } |
||||||
| 57 | $inotify->addExcludedDirs($config['excluded_dirs']); |
||||||
| 58 | $inotify->watch(); |
||||||
| 59 | if ($log) { |
||||||
| 60 | $this->info(sprintf('[Inotify] watched files: %d; file types: %s; excluded directories: %s', |
||||||
|
0 ignored issues
–
show
|
|||||||
| 61 | $inotify->getWatchedFileCount(), |
||||||
|
0 ignored issues
–
show
|
|||||||
| 62 | implode(',', $config['file_types']), |
||||||
|
0 ignored issues
–
show
|
|||||||
| 63 | implode(',', $config['excluded_dirs']) |
||||||
|
0 ignored issues
–
show
|
|||||||
| 64 | ) |
||||||
|
0 ignored issues
–
show
|
|||||||
| 65 | ); |
||||||
| 66 | } |
||||||
| 67 | $inotify->start(); |
||||||
| 68 | }; |
||||||
| 69 | |||||||
| 70 | $process = new Process($callback, false, 0); |
||||||
| 71 | $swoole->addProcess($process); |
||||||
| 72 | return $process; |
||||||
| 73 | } |
||||||
| 74 | } |