diff --git a/.env.example b/.env.example index 5d7646c1..5dec76f1 100644 --- a/.env.example +++ b/.env.example @@ -57,3 +57,6 @@ VITE_PUSHER_HOST="${PUSHER_HOST}" VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +#for documentation +GITHUB_ACCESS_TOKEN= diff --git a/README.md b/README.md index 07481887..a3971ffe 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,23 @@ - Создать запрос на добавление примера кода или статьи. - Добавить ссылки на полезные ресурсы или пакеты. + + +## Установка + +```bash +composer install +php artisan migrate +npm run dev +``` + +## Переменные окружения +```shell +#Для сравнивания документации из Laravel +GITHUB_ACCESS_TOKEN= +``` + + ## Связаться с нами Мы всегда открыты для обратной связи, вопросов и предложений. Вы можете связаться с нами через телеграм: diff --git a/app/Docs.php b/app/Docs.php index 851dce87..4b2a63bf 100644 --- a/app/Docs.php +++ b/app/Docs.php @@ -4,6 +4,8 @@ use App\Models\Document; use Exception; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; @@ -75,26 +77,21 @@ public function __construct(string $version, string $file) try { $this->variables = Yaml::parse($variables); - }catch (\Throwable){ - + } catch (\Throwable) { } } /** * Get the rendered view of a documentation page. * - * @param string $view The view name. - * - * @return \Illuminate\Contracts\View\View The rendered view of the documentation page. - * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ - public function view(string $view) + public function view(string $viewName): View { $content = Str::of($this->page) ->replace('{{version}}', $this->version) - ->replace('{note}','⚠️') - ->replace('{tip}','💡️') + ->replace('{note}', '⚠️') + ->replace('{tip}', '💡️') ->after('---') ->after('---') ->markdown(); @@ -104,7 +101,7 @@ public function view(string $view) 'edit' => $this->goToGitHub(), ]); - return view($view, $all); + return view($viewName, $all); } /** @@ -177,9 +174,9 @@ public function docsToArray(string $html): array * * @param string $version The version of the Laravel documentation. * - * @return \Illuminate\Support\Collection A collection of Docs instances. + * @return Collection A collection of Docs instances. */ - static public function every(string $version): \Illuminate\Support\Collection + public static function every(string $version): Collection { $files = Storage::disk('docs')->allFiles($version); @@ -190,12 +187,7 @@ static public function every(string $version): \Illuminate\Support\Collection ->map(fn(string $path) => new static($version, $path)); } - /** - * Fetch the number of commits behind the current commit. - * - * @return int The number of commits behind. - */ - public function fetchBehind(): int + public function countCommitsBehindCurrent(): int { throw_unless(isset($this->variables['git']), new Exception("Document {$this->path} does not have a git hash")); @@ -235,7 +227,7 @@ public function goToOriginal(): string * * @return string */ - static public function compareLink(string $version, string $hash): string + public static function compareLink(string $version, string $hash): string { $compactHash = Str::of($hash)->limit(7, '')->toString(); @@ -245,7 +237,7 @@ static public function compareLink(string $version, string $hash): string /** * Get the Document model for the documentation page. * - * @return \App\Models\Document The Document model. + * @return Document The Document model. */ public function getModel(): Document { @@ -259,18 +251,18 @@ public function getModel(): Document return $this->model; } - /** - * @return int - */ - public function behind():int + public function countCommitsBehind(): int { - return $this->getModel()->behind; + return $this->getModel()->count_commits_behind; } - /** - * @return string - */ - public function isOlderVersion() + + public function translationIsLagsBehind(): bool + { + return $this->getModel()->count_commits_behind > 0; + } + + public function isOlderVersion(): bool { return $this->version !== static::DEFAULT_VERSION; } @@ -283,7 +275,7 @@ public function isOlderVersion() public function update() { $this->getModel()->fill([ - 'behind' => $this->fetchBehind(), + 'count_commits_behind' => $this->countCommitsBehindCurrent(), 'current_commit' => $this->variables['git'], ])->save(); } diff --git a/app/Http/Controllers/DocsController.php b/app/Http/Controllers/DocsController.php index a17de002..7f3e957b 100644 --- a/app/Http/Controllers/DocsController.php +++ b/app/Http/Controllers/DocsController.php @@ -4,20 +4,16 @@ use App\Docs; use App\Models\Document; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\View; class DocsController extends Controller { /** * Show a documentation page. * - * @param string $version - * @param string $page - * - * @return \Illuminate\View\View * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ - public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation') + public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation'): View { $docs = new Docs($version, $page); @@ -29,15 +25,10 @@ public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'in ]); } - /** - * @param string $version - * - * @return \Illuminate\Contracts\View\View - */ - public function status(string $version = Docs::DEFAULT_VERSION) + public function status(string $version = Docs::DEFAULT_VERSION): View { $documents = Document::where('version', $version) - ->orderByDesc('behind') + ->orderByDesc('count_commits_behind') ->get(); return view('pages.status', [ diff --git a/app/Models/Document.php b/app/Models/Document.php index 5db601db..5015709f 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -9,7 +9,8 @@ class Document extends Model { - use HasFactory, HasUuids; + use HasFactory; + use HasUuids; /** * @var string[] @@ -18,7 +19,7 @@ class Document extends Model 'id', 'version', 'file', - 'behind', + 'count_commits_behind', 'current_commit', 'last_commit', ]; @@ -28,6 +29,6 @@ class Document extends Model */ protected $attributes = [ 'version' => Docs::DEFAULT_VERSION, - 'behind' => 0, + 'count_commits_behind' => 0, ]; } diff --git a/composer.json b/composer.json index 9446192a..20443c9b 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^7.0", "phpunit/phpunit": "^10.1", - "spatie/laravel-ignition": "^2.0" + "spatie/laravel-ignition": "^2.0", + "squizlabs/php_codesniffer": "3.*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index ba968616..80d43158 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "76f5c0233ee741c7257c0c9be5b27318", + "content-hash": "45802c924840e597ac0e81f8ed4b6dd5", "packages": [ { "name": "brick/math", @@ -6478,16 +6478,16 @@ }, { "name": "filp/whoops", - "version": "2.15.3", + "version": "2.15.4", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "c83e88a30524f9360b11f585f71e6b17313b7187" + "reference": "a139776fa3f5985a50b509f2a02ff0f709d2a546" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/c83e88a30524f9360b11f585f71e6b17313b7187", - "reference": "c83e88a30524f9360b11f585f71e6b17313b7187", + "url": "https://api.github.com/repos/filp/whoops/zipball/a139776fa3f5985a50b509f2a02ff0f709d2a546", + "reference": "a139776fa3f5985a50b509f2a02ff0f709d2a546", "shasum": "" }, "require": { @@ -6537,7 +6537,7 @@ ], "support": { "issues": "https://github.com/filp/whoops/issues", - "source": "https://github.com/filp/whoops/tree/2.15.3" + "source": "https://github.com/filp/whoops/tree/2.15.4" }, "funding": [ { @@ -6545,7 +6545,7 @@ "type": "github" } ], - "time": "2023-07-13T12:00:00+00:00" + "time": "2023-11-03T12:00:00+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -8724,6 +8724,63 @@ ], "time": "2023-10-09T12:55:26+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2023-02-22T23:07:41+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -8784,5 +8841,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/database/migrations/2023_10_28_020135_create_posts_table.php b/database/migrations/2023_10_28_020135_create_posts_table.php index c3831e6b..648245a1 100644 --- a/database/migrations/2023_10_28_020135_create_posts_table.php +++ b/database/migrations/2023_10_28_020135_create_posts_table.php @@ -14,6 +14,7 @@ public function up(): void Schema::create('posts', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('user_id'); + $table->string('status', 15); $table->string('title'); $table->text('content'); $table->string('slug')->unique(); diff --git a/database/migrations/2023_10_28_212457_create_documents_table.php b/database/migrations/2023_10_28_212457_create_documents_table.php index 98c18ddd..f89ee219 100644 --- a/database/migrations/2023_10_28_212457_create_documents_table.php +++ b/database/migrations/2023_10_28_212457_create_documents_table.php @@ -13,11 +13,11 @@ public function up(): void { Schema::create('documents', function (Blueprint $table) { $table->uuid('id'); - $table->string('version'); + $table->string('version', 7); $table->string('file'); - $table->integer('behind')->default(0); - $table->string('current_commit')->nullable(); - $table->string('last_commit')->nullable(); + $table->unsignedInteger('count_commits_behind')->default(0)->comment('count commits behind current'); + $table->string('current_commit', 64)->nullable(); + $table->string('last_commit', 64)->nullable(); $table->timestamps(); diff --git a/resources/views/pages/docs.blade.php b/resources/views/pages/docs.blade.php index 0ecf430c..20ed599d 100644 --- a/resources/views/pages/docs.blade.php +++ b/resources/views/pages/docs.blade.php @@ -44,8 +44,8 @@ class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline
- @if($docs->behind() > 0) - Перевод отстаёт на {{ $docs->behind() }} изменения + @if($docs->translationIsLagsBehind()) + Перевод отстаёт на {{ $docs->countCommitsBehind() }} изменения @else Перевод актуален @endif diff --git a/resources/views/pages/profile.blade.php b/resources/views/pages/profile.blade.php index a309bb8c..6546a164 100644 --- a/resources/views/pages/profile.blade.php +++ b/resources/views/pages/profile.blade.php @@ -15,7 +15,7 @@
+ src="{{ auth()->user()?->avatar }}" alt="">
diff --git a/resources/views/pages/status.blade.php b/resources/views/pages/status.blade.php index 5dc7b04d..892044a7 100644 --- a/resources/views/pages/status.blade.php +++ b/resources/views/pages/status.blade.php @@ -43,13 +43,14 @@ class="{{ $current === $version ? 'link-primary' : 'link-body-emphasis' }} text-
@foreach($documents as $doc) +
{{ $doc->file }}
- @if($doc->behind > 0) + @if($doc->count_commits_behind > 0) - Перевод отстаёт на {{ $doc->behind }} изменения + Перевод отстаёт на {{ $doc->count_commits_behind }} изменения @else Перевод актуален