GalleryClearCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 6
rs 9.4285
c 2
b 0
f 1
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace JeroenG\LaravelPhotoGallery\Console;
4
5
use Illuminate\Console\Command;
6
use JeroenG\LaravelPhotoGallery\Contracts\AlbumAdapter;
7
use JeroenG\LaravelPhotoGallery\Contracts\PhotoAdapter;
8
9
class GalleryClearCommand extends Command
10
{
11
12
	/**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
	protected $signature = 'gallery:clear';
18
19
	/**
20
	 * The console command description.
21
	 *
22
	 * @var string
23
	 */
24
	protected $description = 'Remove all photos and albums';
25
26
	/**
27
	 * Create a new command instance.
28
	 *
29
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
	 */
31
	public function __construct(AlbumAdapter $albums, PhotoAdapter $photos)
32
	{
33
		parent::__construct();
34
		$this->photos = $photos;
35
		$this->albums = $albums;
36
	}
37
38
	/**
39
	 * Execute the console command.
40
	 *
41
	 * @return mixed
42
	 */
43
	public function handle()
44
	{
45
		$this->comment('Deleting photos...');
46
		$allPhotos = $this->photos->all();
47
		foreach ($allPhotos as $photo) {
48
			$this->photos->delete($photo);
49
		}
50
51
		$this->comment('Deleting albums...');
52
		$allAlbums = $this->albums->all();
53
		foreach ($allAlbums as $album) {
54
			if($album->getId() != 1)
55
			{
56
				$this->albums->delete($album);
57
			}
58
		}
59
60
		$this->info('Gallery cleared!');
61
	}
62
63
}