Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( f24ad2...91ea33 )
by Cristian
07:08
created

BackupController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 14
c 7
b 2
f 1
lcom 0
cbo 2
dl 0
loc 100
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
C index() 0 35 7
A create() 0 18 2
A download() 0 21 3
A delete() 0 14 2
1
<?php namespace Backpack\BackupManager\app\Http\Controllers;
2
3
use App\Http\Requests;
4
use App\Http\Controllers\Controller;
5
use Illuminate\Http\Request;
6
use Auth;
7
use App;
8
use Storage;
9
use Carbon\Carbon;
10
use Artisan;
11
use Log;
12
13
class BackupController extends Controller {
14
15
	public function index()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
16
	{
17
		if (!count(config('laravel-backup.backup.destination.disks'))) {
18
			dd(trans('backpack::backup.no_disks_configured'));
19
		}
20
21
		$this->data['backups'] = [];
22
23
		foreach (config('laravel-backup.backup.destination.disks') as $disk_name) {
24
			$disk = Storage::disk($disk_name);
25
			$adapter = $disk->getDriver()->getAdapter();
26
			$files = $disk->files();
27
28
			// make an array of backup files, with their filesize and creation date
29
			foreach ($files as $k => $f) {
30
				// only take the zip files into account
31
				if (substr($f, -4) == '.zip' && $disk->exists($f)) {
32
					$this->data['backups'][] = [
33
						'file_path' => $f,
34
						'file_name' => str_replace('backups/', '', $f),
35
						'file_size' => $disk->size($f),
36
						'last_modified' => $disk->lastModified($f),
37
						'disk' => $disk_name,
38
						'download' => ($adapter instanceof \League\Flysystem\Adapter\Local)?true:false
39
						];
40
				}
41
			}
42
		}
43
44
		// reverse the backups, so the newest one would be on top
45
		$this->data['backups'] = array_reverse($this->data['backups']);
46
		$this->data['title'] = 'Backups';
47
48
		return view("backupmanager::backup", $this->data);
49
	}
50
51
	public function create()
52
	{
53
	    try {
54
	      ini_set('max_execution_time', 300);
55
	      // start the backup process
56
	      Artisan::call('backup:run');
57
	      $output = Artisan::output();
58
59
	      // log the results
60
	      Log::info("Backpack\BackupManager -- new backup started from admin interface \r\n".$output);
61
	      // return the results as a response to the ajax call
62
	      echo($output);
63
	    } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Backpack\BackupManager\a...p\Controllers\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
64
	      Response::make($e->getMessage(), 500);
65
	    }
66
67
	    return 'success';
68
	}
69
70
	/**
71
	 * Downloads a backup zip file.
72
	 */
73
	public function download($file_name)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Coding Style Naming introduced by
The parameter $file_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
74
	{
75
		$disk = Storage::disk(\Request::input('disk'));
76
		$adapter = $disk->getDriver()->getAdapter();
77
78
		if ($adapter instanceof \League\Flysystem\Adapter\Local) {
79
			$storage_path = $disk->getDriver()->getAdapter()->getPathPrefix();
80
81
			if ($disk->exists($file_name)) {
82
				return response()->download($storage_path.$file_name);
83
			}
84
			else
85
			{
86
				abort(404, trans('backpack::backup.backup_doesnt_exist'));
87
			}
88
		}
89
		else
90
		{
91
			abort(404, trans('backpack::backup.only_local_downloads_supported'));
92
		}
93
	}
94
95
	/**
96
	 * Deletes a backup file.
97
	 */
98
	public function delete($file_name)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $file_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
99
	{
100
		$disk = Storage::disk(\Request::input('disk'));
101
102
		if ($disk->exists($file_name)) {
103
			$disk->delete($file_name);
104
105
			return 'success';
106
		}
107
		else
108
		{
109
			abort(404, trans('backpack::backup.backup_doesnt_exist'));
110
		}
111
	}
112
}
113