Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
azzarip authored and github-actions[bot] committed Jan 3, 2024
1 parent c2e7f88 commit 211a386
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Azzarip\NotaCMS;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use RalphJSmit\Laravel\SEO\Support\HasSEO;
use Spatie\YamlFrontMatter\YamlFrontMatter;

Expand Down Expand Up @@ -38,8 +38,8 @@ public static function findSlug(string $slug): ?Blog

public static function loadFile(string $fileName): ?Blog
{
$path = self::getPath() . $fileName . '.md';
if (!File::exists($path)) {
$path = self::getPath().$fileName.'.md';
if (! File::exists($path)) {
return null;
}

Expand All @@ -65,12 +65,12 @@ public static function loadFile(string $fileName): ?Blog

private function getFilePath(): string
{
return $this->getPath() . $this->slug . '.md';
return $this->getPath().$this->slug.'.md';

Check failure on line 68 in src/Blog.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Azzarip\NotaCMS\Blog::$slug.
}

public static function getPath(): string
{
return base_path('content/notacms/') . self::getRoute() . '/';
return base_path('content/notacms/').self::getRoute().'/';
}

public static function getRoute()
Expand Down
11 changes: 6 additions & 5 deletions src/Commands/Actions/CreateContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Azzarip\NotaCMS\Commands\Actions;

use Illuminate\Support\Facades\File;

class CreateContent {

public static function create(string $blog){

class CreateContent
{
public static function create(string $blog)
{
$contentPath = base_path('content/notacms');
if (! File::exists($contentPath)) {
File::makeDirectory($contentPath, 0755, true);
Expand All @@ -20,5 +21,5 @@ public static function create(string $blog){
$content = File::get(__DIR__.'/../../../stubs/post.stub');
File::put($contentPath.'/my-first-post.md', $content);
}
}
}
};
16 changes: 9 additions & 7 deletions src/Commands/LoadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Azzarip\NotaCMS\Commands;

use Illuminate\Support\Arr;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;

class LoadCommand extends Command
Expand All @@ -19,26 +19,28 @@ public function handle(): int

if (! $blog) {
$blogs = array_keys(config('notacms'));
$blog = $this->choice("Which blog you want to load to database?",
Arr::prepend($blogs, 'all'),
$default='all');
$blog = $this->choice('Which blog you want to load to database?',
Arr::prepend($blogs, 'all'),
$default = 'all');
}

if($blog === 'all') {
if ($blog === 'all') {
foreach ($blogs as $blog) {
$this->loadBlog($blog);
$this->comment('All files loaded for: ' . $blog);
$this->comment('All files loaded for: '.$blog);
}

return self::SUCCESS;
}

$this->loadBlog($blog);

return self::SUCCESS;
}

private function loadBlog(string $blog): void
{
$files = File::files(base_path('content/notacms/' . $blog));
$files = File::files(base_path('content/notacms/'.$blog));
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'md') {
$slug = pathinfo($file, PATHINFO_FILENAME);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Azzarip\NotaCMS\Commands;

use Illuminate\Support\Str;
use Azzarip\NotaCMS\Commands\Actions\CreateContent;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Azzarip\NotaCMS\Commands\Actions\CreateContent;
use Illuminate\Support\Str;

class NewCommand extends Command
{
Expand Down
1 change: 0 additions & 1 deletion src/NotaCMSServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Azzarip\NotaCMS\Commands\LoadCommand;
use Azzarip\NotaCMS\Commands\NewCommand;
use Illuminate\Support\Facades\File;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down
7 changes: 4 additions & 3 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

use Azzarip\NotaCMS\Blog;
use Illuminate\Support\Facades\File;
use Azzarip\NotaCMS\Commands\Actions\CreateContent;
use Illuminate\Support\Facades\File;

beforeEach(function () {
$filePath = base_path('content/notacms/blog/my-first-post.md');
if(!File::exists($filePath)) {
if (! File::exists($filePath)) {
CreateContent::create('blog');
}
$post = Blog::loadFile('my-first-post');});
$post = Blog::loadFile('my-first-post');
});

it('creates a blog from file', function () {
$post = Blog::loadFile('my-first-post');
Expand Down
5 changes: 2 additions & 3 deletions tests/LoadCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

use Azzarip\NotaCMS\Blog;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Artisan;
use Azzarip\NotaCMS\Commands\Actions\CreateContent;
use Illuminate\Support\Facades\File;

beforeEach(function () {
$filePath = base_path('content/notacms/blog/my-first-post.md');
if(!File::exists($filePath)) {
if (! File::exists($filePath)) {
CreateContent::create('blog');
}
});
Expand Down
9 changes: 5 additions & 4 deletions tests/ShowTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Azzarip\NotaCMS\Blog;
use function Pest\Laravel\get;
use Illuminate\Support\Facades\File;
use Azzarip\NotaCMS\Commands\Actions\CreateContent;
use Illuminate\Support\Facades\File;

use function Pest\Laravel\get;

beforeEach(function () {
$filePath = base_path('content/notacms/blog/my-first-post.md');
if(!File::exists($filePath)) {
if (! File::exists($filePath)) {
CreateContent::create('blog');
}
$post = Blog::loadFile('my-first-post');
Expand Down Expand Up @@ -35,4 +36,4 @@
File::cleanDirectory(database_path('Migrations'));
File::cleanDirectory(app_path('content'));
File::cleanDirectory(resource_path('views/vendor/notacms/testblog'));
});
});

0 comments on commit 211a386

Please sign in to comment.