Skip to content

Commit c6a0740

Browse files
avvertixactions-user
authored andcommitted
Fix styling
1 parent 13e43e5 commit c6a0740

File tree

5 files changed

+96
-100
lines changed

5 files changed

+96
-100
lines changed
Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,88 @@
1-
<?php
2-
3-
namespace Oneofftech\LaravelLanguageRecognizer\Commands;
4-
5-
use Exception;
6-
use Illuminate\Console\Command;
7-
use Illuminate\Support\Str;
8-
use Illuminate\Support\Facades\Http;
9-
10-
class InstallLocalRecognizerCommand extends Command
11-
{
12-
public $signature = 'language-recognizer:install-local-driver {--path=}';
13-
14-
public $description = 'Install the local Franc binary used to recognize the language of a text';
15-
16-
17-
/**
18-
* Artifacts urls keyed based on operating system
19-
*
20-
* @var array
21-
*/
22-
protected static $urls = [
23-
'linux' => 'https://github.com/avvertix/franc-bin/releases/download/v1.0.0/franc-bin-linux',
24-
'darwin' => 'https://github.com/avvertix/franc-bin/releases/download/v1.0.0/franc-bin-macos',
25-
'winnt' => 'https://github.com/avvertix/franc-bin/releases/download/v1.0.0/franc-bin-win.exe',
26-
];
27-
28-
29-
/**
30-
* @return int
31-
*
32-
*/
33-
public function handle()
34-
{
35-
$this->comment('Downloading Franc from binary from https://github.com/avvertix/franc-bin');
36-
37-
$os = $this->getOs();
38-
39-
$url = self::$urls[$os] ?? null;
40-
41-
if(is_null($url)){
42-
throw new Exception("Unsupported operating system [{$os}]");
43-
}
44-
45-
$this->info($url);
46-
47-
$downloadPath = $this->getDownloadPath();
48-
49-
if(!is_dir($directory = dirname($downloadPath))){
50-
mkdir($directory);
51-
}
52-
53-
Http::withOptions([
54-
'sink' => $downloadPath,
55-
])->timeout(30)->get($url);
56-
57-
$this->comment('All done');
58-
59-
return 0;
60-
}
61-
62-
protected function getOs()
63-
{
64-
return strtolower(PHP_OS);
65-
}
66-
67-
protected function getDownloadPath()
68-
{
69-
$pathOption = $this->option('path');
70-
71-
if($pathOption){
72-
73-
if($this->getOs() === 'winnt' && ! Str::endsWith($pathOption, '.exe')){
74-
return $pathOption.'.exe';
75-
}
76-
77-
return $pathOption;
78-
}
79-
80-
$suffixes = [
81-
'winnt' => '.exe',
82-
];
83-
84-
$configuredPath = config('language-recognizer.drivers.local.path');
85-
86-
$resolvedPath = Str::startsWith($configuredPath, '.') ? base_path($configuredPath) : $configuredPath;
87-
88-
return $resolvedPath . ($suffixes[$this->getOs()] ?? '');
89-
}
90-
}
1+
<?php
2+
3+
namespace Oneofftech\LaravelLanguageRecognizer\Commands;
4+
5+
use Exception;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Http;
8+
use Illuminate\Support\Str;
9+
10+
class InstallLocalRecognizerCommand extends Command
11+
{
12+
public $signature = 'language-recognizer:install-local-driver {--path=}';
13+
14+
public $description = 'Install the local Franc binary used to recognize the language of a text';
15+
16+
17+
/**
18+
* Artifacts urls keyed based on operating system
19+
*
20+
* @var array
21+
*/
22+
protected static $urls = [
23+
'linux' => 'https://github.com/avvertix/franc-bin/releases/download/v1.0.0/franc-bin-linux',
24+
'darwin' => 'https://github.com/avvertix/franc-bin/releases/download/v1.0.0/franc-bin-macos',
25+
'winnt' => 'https://github.com/avvertix/franc-bin/releases/download/v1.0.0/franc-bin-win.exe',
26+
];
27+
28+
/**
29+
* @return int
30+
*
31+
*/
32+
public function handle()
33+
{
34+
$this->comment('Downloading Franc from binary from https://github.com/avvertix/franc-bin');
35+
36+
$os = $this->getOs();
37+
38+
$url = self::$urls[$os] ?? null;
39+
40+
if (is_null($url)) {
41+
throw new Exception("Unsupported operating system [{$os}]");
42+
}
43+
44+
$this->info($url);
45+
46+
$downloadPath = $this->getDownloadPath();
47+
48+
if (! is_dir($directory = dirname($downloadPath))) {
49+
mkdir($directory);
50+
}
51+
52+
Http::withOptions([
53+
'sink' => $downloadPath,
54+
])->timeout(30)->get($url);
55+
56+
$this->comment('All done');
57+
58+
return 0;
59+
}
60+
61+
protected function getOs()
62+
{
63+
return strtolower(PHP_OS);
64+
}
65+
66+
protected function getDownloadPath()
67+
{
68+
$pathOption = $this->option('path');
69+
70+
if ($pathOption) {
71+
if ($this->getOs() === 'winnt' && ! Str::endsWith($pathOption, '.exe')) {
72+
return $pathOption.'.exe';
73+
}
74+
75+
return $pathOption;
76+
}
77+
78+
$suffixes = [
79+
'winnt' => '.exe',
80+
];
81+
82+
$configuredPath = config('language-recognizer.drivers.local.path');
83+
84+
$resolvedPath = Str::startsWith($configuredPath, '.') ? base_path($configuredPath) : $configuredPath;
85+
86+
return $resolvedPath . ($suffixes[$this->getOs()] ?? '');
87+
}
88+
}

src/Drivers/LocalLanguageRecognizerDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class LocalLanguageRecognizerDriver implements LanguageRecognizer
1414
{
1515
/**
1616
* The path of the Franc binary
17-
*
17+
*
1818
* @var string
1919
*/
2020
protected $binaryPath;
@@ -29,7 +29,7 @@ public function __construct($config)
2929
}
3030

3131
/**
32-
*
32+
*
3333
* @param string $configuredPath
3434
* @return string
3535
* @throws \InvalidArgumentException

src/LaravelLanguageRecognizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function driver($driver = null)
2828

2929
/**
3030
* @return \Oneofftech\LaravelLanguageRecognizer\Drivers\LocalLanguageRecognizerDriver
31-
*
31+
*
3232
* @psalm-suppress UndefinedInterfaceMethod
3333
*/
3434
protected function createLocalDriver()
@@ -40,7 +40,7 @@ protected function createLocalDriver()
4040
* Get the default driver name.
4141
*
4242
* @return string
43-
*
43+
*
4444
* @psalm-suppress UndefinedInterfaceMethod
4545
*/
4646
public function getDefaultDriver()

src/LaravelLanguageRecognizerServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ class LaravelLanguageRecognizerServiceProvider extends ServiceProvider
1010
public function boot(): void
1111
{
1212
if ($this->app->runningInConsole()) {
13-
1413
$this->commands([
1514
InstallLocalRecognizerCommand::class,
1615
]);
17-
16+
1817
$this->publishes([
1918
__DIR__.'/../config/language-recognizer.php' => config_path('language-recognizer.php'),
2019
]);

tests/Integration/InstallCommandTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public function download_the_franc_binary_to_custom_path()
1212
$exit = Artisan::call('language-recognizer:install-local-driver', ['--path' => __DIR__ . '/../../bin/language-guesser']);
1313

1414
$this->assertEquals(0, $exit);
15-
$this->assertFileExists(__DIR__ . '/../../bin/language-guesser' . (strtolower(PHP_OS) === 'winnt' ?'.exe':'' ));
15+
$this->assertFileExists(__DIR__ . '/../../bin/language-guesser' . (strtolower(PHP_OS) === 'winnt' ? '.exe' : ''));
1616
}
17-
17+
1818
/** @test */
1919
public function download_the_franc_binary_to_default_path()
2020
{
@@ -23,7 +23,6 @@ public function download_the_franc_binary_to_default_path()
2323
$exit = Artisan::call('language-recognizer:install-local-driver');
2424

2525
$this->assertEquals(0, $exit);
26-
$this->assertFileExists(base_path('bin/language-guesser') . (strtolower(PHP_OS) === 'winnt' ?'.exe':'' ));
26+
$this->assertFileExists(base_path('bin/language-guesser') . (strtolower(PHP_OS) === 'winnt' ? '.exe' : ''));
2727
}
28-
2928
}

0 commit comments

Comments
 (0)