PanovAlexey /
laravel-yandex-speller-package
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace CodeblogPro\YandexSpeller\Controller; |
||||
| 4 | |||||
| 5 | use Illuminate\Routing\Controller; |
||||
| 6 | use CodeblogPro\YandexSpeller\Application\Services\YandexSpeller\YandexSpellerService; |
||||
| 7 | |||||
| 8 | class YandexSpellerController extends Controller |
||||
| 9 | { |
||||
| 10 | public function index(?string $sourceString = '') |
||||
| 11 | { |
||||
| 12 | if (!empty($sourceString)) { |
||||
| 13 | try { |
||||
| 14 | $yandexSpellerService = resolve(YandexSpellerService::class); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 15 | $yandexSpellerAnswer = $yandexSpellerService->getAnswerByString($sourceString); |
||||
| 16 | } catch (\Throwable $throwable) { |
||||
| 17 | $yandexSpellerAnswer = null; |
||||
| 18 | } |
||||
| 19 | |||||
| 20 | if (empty($yandexSpellerAnswer)) { |
||||
| 21 | $result = [ |
||||
| 22 | 'status' => 500, |
||||
| 23 | 'body' => ['error' => ['message' => 'Internal error. Please, try again later']] |
||||
| 24 | ]; |
||||
| 25 | } else { |
||||
| 26 | $result = [ |
||||
| 27 | 'status' => 200, |
||||
| 28 | 'body' => [ |
||||
| 29 | 'source_string' => $yandexSpellerAnswer->getSourceString(), |
||||
| 30 | 'corrected_array' => $yandexSpellerAnswer->getCorrectedArray(), |
||||
| 31 | ] |
||||
| 32 | ]; |
||||
| 33 | } |
||||
| 34 | } else { |
||||
| 35 | $result = [ |
||||
| 36 | 'status' => 400, |
||||
| 37 | 'body' => ['error' => ['message' => 'Invalid string']] |
||||
| 38 | ]; |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | return response()->json($result['body'], $result['status']); |
||||
|
0 ignored issues
–
show
The function
response was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 42 | } |
||||
| 43 | |||||
| 44 | public function incorrectMethod() |
||||
| 45 | { |
||||
| 46 | $result = [ |
||||
| 47 | 'status' => 405, |
||||
| 48 | 'body' => ['error' => ['message' => 'Method Not Allowed']] |
||||
| 49 | ]; |
||||
| 50 | |||||
| 51 | return response()->json($result['body'], $result['status']); |
||||
|
0 ignored issues
–
show
The function
response was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 52 | } |
||||
| 53 | } |
||||
| 54 |