| Conditions | 2 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 30 | public function register() |
||
| 31 | { |
||
| 32 | // Automatically apply the package configuration |
||
| 33 | $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'laravel-ffmpeg'); |
||
| 34 | |||
| 35 | $this->app->singleton('laravel-ffmpeg-logger', function () { |
||
| 36 | return $this->app['config']->get('laravel-ffmpeg.enable_logging', true) |
||
| 37 | ? app(LoggerInterface::class) |
||
| 38 | : null; |
||
| 39 | }); |
||
| 40 | |||
| 41 | $this->app->singleton('laravel-ffmpeg-configuration', function () { |
||
| 42 | $config = $this->app['config']; |
||
| 43 | |||
| 44 | return [ |
||
| 45 | 'ffmpeg.binaries' => $config->get('laravel-ffmpeg.ffmpeg.binaries'), |
||
| 46 | 'ffmpeg.threads' => $config->get('laravel-ffmpeg.ffmpeg.threads', 12), |
||
| 47 | 'ffprobe.binaries' => $config->get('laravel-ffmpeg.ffprobe.binaries'), |
||
| 48 | 'timeout' => $config->get('laravel-ffmpeg.timeout'), |
||
| 49 | ]; |
||
| 50 | }); |
||
| 51 | |||
| 52 | $this->app->singleton(FFProbe::class, function () { |
||
| 53 | return FFProbe::create( |
||
| 54 | $this->app->make('laravel-ffmpeg-configuration'), |
||
| 55 | $this->app->make('laravel-ffmpeg-logger') |
||
| 56 | ); |
||
| 57 | }); |
||
| 58 | |||
| 59 | $this->app->singleton(FFMpegDriver::class, function () { |
||
| 60 | return FFMpegDriver::create( |
||
| 61 | $this->app->make('laravel-ffmpeg-logger'), |
||
| 62 | $this->app->make('laravel-ffmpeg-configuration') |
||
| 63 | ); |
||
| 64 | }); |
||
| 65 | |||
| 66 | $this->app->singleton(FFMpeg::class, function () { |
||
| 67 | return new FFMpeg( |
||
| 68 | $this->app->make(FFMpegDriver::class), |
||
| 69 | $this->app->make(FFProbe::class) |
||
| 70 | ); |
||
| 71 | }); |
||
| 72 | |||
| 73 | $this->app->singleton(PHPFFMpeg::class, function () { |
||
| 74 | return new PHPFFMpeg($this->app->make(FFMpeg::class)); |
||
| 75 | }); |
||
| 76 | |||
| 77 | $this->app->singleton(TemporaryDirectories::class, function () { |
||
| 78 | return new TemporaryDirectories( |
||
| 79 | $this->app['config']->get('laravel-ffmpeg.temporary_files_root', sys_get_temp_dir()), |
||
| 80 | ); |
||
| 81 | }); |
||
| 82 | |||
| 83 | // Register the main class to use with the facade |
||
| 84 | $this->app->singleton('laravel-ffmpeg', function () { |
||
| 85 | return new MediaOpenerFactory( |
||
| 86 | $this->app['config']->get('filesystems.default'), |
||
| 87 | $this->app->make(PHPFFMpeg::class) |
||
| 88 | ); |
||
| 92 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: