Skip to content

Commit d945a2a

Browse files
committed
fix(ci): resolve type error and simplify workflow
1 parent 5337953 commit d945a2a

File tree

6 files changed

+414
-379
lines changed

6 files changed

+414
-379
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,14 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212

13-
services:
14-
mysql:
15-
image: mysql:8.4
16-
env:
17-
MYSQL_ROOT_PASSWORD: 123456
18-
MYSQL_DATABASE: laravel_test
19-
ports:
20-
- 3306:3306
21-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
22-
2313
steps:
2414
- uses: actions/checkout@v4
2515

2616
- name: Setup PHP 8.4
2717
uses: shivammathur/setup-php@v2
2818
with:
2919
php-version: 8.4
30-
extensions: gd, zip, pdo_mysql, mbstring, curl, xml, bcmath, exif, intl, opcache
31-
coverage: xdebug
20+
extensions: gd, zip, pdo, pdo_sqlite, mbstring, curl, xml, bcmath, exif, intl, opcache
3221

3322
- name: Copy environment file
3423
run: cp app-laravel/api-laravel/.env.example app-laravel/api-laravel/.env
@@ -41,9 +30,14 @@ jobs:
4130
working-directory: app-laravel/api-laravel
4231
run: php artisan key:generate
4332

44-
- name: Run database migrations
33+
- name: Create storage directories
4534
working-directory: app-laravel/api-laravel
46-
run: php artisan migrate --force
35+
run: |
36+
mkdir -p storage/logs
37+
mkdir -p storage/framework/cache
38+
mkdir -p storage/framework/sessions
39+
mkdir -p storage/framework/views
40+
chmod -R 775 storage
4741
4842
- name: Run tests
4943
working-directory: app-laravel/api-laravel

app-laravel/api-laravel/app/Models/Post.php

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use App\Http\Controllers\PostController;
88
use Carbon\Carbon;
9-
use Exception;
9+
use Illuminate\Database\Eloquent\Casts\Attribute;
1010
use Illuminate\Database\Eloquent\Factories\HasFactory;
1111
use Illuminate\Database\Eloquent\Model;
1212
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -17,7 +17,6 @@
1717
use Illuminate\Support\Facades\Request;
1818
use Illuminate\Support\Facades\Storage;
1919
use Illuminate\Support\Str;
20-
use InvalidArgumentException;
2120

2221
/**
2322
* Class Post.
@@ -42,6 +41,20 @@ class Post extends Model
4241

4342
protected $fillable = ['title', 'content', 'date', 'description', 'views_count'];
4443

44+
protected $casts = [
45+
'date' => 'string',
46+
];
47+
48+
public function setDateAttribute($value): void
49+
{
50+
if (empty($value)) {
51+
$this->attributes['date'] = null;
52+
return;
53+
}
54+
55+
$this->attributes['date'] = Carbon::parse($value)->format('Y-m-d');
56+
}
57+
4558
public function category(): BelongsTo
4659
{
4760
return $this->belongsTo(Category::class);
@@ -182,40 +195,6 @@ public function toggleFeatured($value): void
182195
$this->setFeatured();
183196
}
184197

185-
public function setDateAttribute($value): void
186-
{
187-
if (empty($value)) {
188-
$this->attributes['date'] = null;
189-
return;
190-
}
191-
192-
try {
193-
$date = Carbon::createFromFormat('Y-m-d', $value);
194-
if ($date !== false) {
195-
$this->attributes['date'] = $date->format('Y-m-d');
196-
return;
197-
}
198-
} catch (Exception $e) {
199-
// Continue to try Carbon::parse
200-
}
201-
202-
try {
203-
$date = Carbon::parse($value);
204-
$this->attributes['date'] = $date->format('Y-m-d');
205-
} catch (Exception $parseException) {
206-
$this->attributes['date'] = null;
207-
}
208-
}
209-
210-
public function getDateAttribute(): ?string
211-
{
212-
if (isset($this->attributes['date']) && !empty($this->attributes['date'])) {
213-
return $this->attributes['date'];
214-
}
215-
216-
return null;
217-
}
218-
219198
public function getCategoryTitle(): string
220199
{
221200
return $this->category->title ?? 'Нет категории';
@@ -288,7 +267,7 @@ public function getDescription(): string
288267
{
289268
return empty($this->description)
290269
? 'Справочник по тематике программирования на языках PHP, JS'
291-
: strip_tags($this->description);
270+
: strip_tags((string)$this->description);
292271
}
293272

294273
public function getTitle(): string
@@ -304,15 +283,8 @@ public function getTitle(): string
304283
return $this->title;
305284
}
306285

307-
/* Аксессор для получения количества лайков, $post->likes_count*/
308-
// public function getLikesCountAttribute()
309-
// {
310-
// return $this->likes()->where('post_id', $this->id)->count();
311-
// }
312-
313-
/* Аксессор для определения поставлен ли лайк этим пользователем, $post->is_liked */
314-
public function getIsLikedAttribute(): bool
286+
protected function isLiked(): Attribute
315287
{
316-
return PostController::isLiked($this->id);
288+
return Attribute::make(get: fn() => PostController::isLiked($this->id));
317289
}
318290
}

app-laravel/api-laravel/bootstrap/app.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ function locateBasePath($app): string
3838
return $underBuild;
3939
}
4040

41-
return $inBuild;
41+
if ($inBuild !== false) {
42+
return $inBuild;
43+
}
44+
45+
// Fallback to default storage path
46+
return $app->basePath() . DIRECTORY_SEPARATOR . 'storage';
4247
}
4348
}
4449
$app->useStoragePath(locateBasePath($app));

app-laravel/api-laravel/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"guzzlehttp/guzzle": "^7.0.1",
1818
"itsgoingd/clockwork": "^5.0",
1919
"jenssegers/agent": "^2.6",
20-
"laravel/framework": "^11.0",
20+
"laravel/framework": "^12.0",
2121
"laravel/helpers": "^1.2",
2222
"laravel/telescope": "^5.3",
2323
"laravel/tinker": "^2.0",
@@ -37,7 +37,7 @@
3737
"phpstan/phpstan-beberlei-assert": "*",
3838
"phpstan/phpstan-phpunit": "*",
3939
"phpstan/phpstan-strict-rules": "^2.0",
40-
"phpunit/phpunit": "^10.0",
40+
"phpunit/phpunit": "^11.0",
4141
"rector/rector": "^2.0",
4242
"driftingly/rector-laravel": "^2.0.5",
4343
"spatie/laravel-ignition": "^2.8"

0 commit comments

Comments
 (0)