Completed
Push — master ( 3404b3...33d684 )
by Taavo-Taur
07:35
created

AdminController::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
//namespace Admin;
4
5
use Illuminate\Support\Facades\Input;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Input.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Krucas\Notification\Facades\Notification;
7
use Illuminate\Support\Facades\Redirect;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Redirect.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use Carbon\Carbon;
9
use Goutte\Client;
10
use Symfony\Component\DomCrawler\Crawler;
11
class AdminController extends \AdminBaseController {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
13
	/**
14
	 * Admin Homepage
15
	 */
16
	public function index() {
17
		$stats = [
18
			'users' => User::count(),
19
			'leagues' => League::count(),
20
			'movies' => Movie::count(),
21
		];
22
23
24
		$this->layout->title = 'Admin';
25
		$this->layout->content = View::make('admin.index', compact('stats'));
26
	}
27
	
28
	public function movies() {
29
		$movies_query = Movie::query();
30
		$movies_query->orderBy('release', 'desc');
31
		$movies_query->select('movies.*');
32
		$movies = $movies_query->paginate(1000);
33
		$this->layout->title = 'Movies';
34
		$this->layout->content = View::make('admin.movies',compact('movies'));
35
	}
36
	private function getUrl($mojoid) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
37
		return 'http://www.boxofficemojo.com/daily/chart/?view=1day&sortdate=' . $date->toDateString();
0 ignored issues
show
Bug introduced by
The variable $date does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
38
	}
39
40
	public function addMovie() {
41
		$mojo_id = str_replace(".htm",'',Input::get('movie'));
42
		$info = new stdClass();
43
		$info->found = false;
44
		$info->mojo_id = $mojo_id;
45
		if ($mojo_id != '')
46
		{
47
			$client = new Client();
48
			$crawler = $client->request('GET', 'http://www.boxofficemojo.com/movies/?page=daily&view=chart&id='.$mojo_id.'.htm', [], [], [
49
				'HTTP_USER_AGENT' => "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
50
			]);
51
			
52
			
53
			$info->title = $crawler->filterXPath("//div[@id='body']//font[@face='Verdana']/b")->text();
54
			$info->release_date = new Carbon($crawler->filterXPath("//div[@id='body']//td[starts-with(.,'Release Date')]//a")->text());
55
			
56
			$info->grosses = $crawler->filter('#body table[border="0"][class="chart-wide"] tr[bgcolor]:not([bgcolor="#dcdcdc"])')->each(function(Crawler $node) {
57
				$cols = $node->children();
58
59
				$myinfo = [
60
					'release_date'   => new Carbon($cols->eq(1)->text()),
61
					'domestic_total' => intval(str_replace(['$', ','], '', $cols->eq(8)->text())),
62
				];
63
				
64
				return $myinfo;
65
			});
66
			
67
			$info->found = true;
68
			
69
			
70
			//Notification::success($title." ".$release_date." ".$boxmojo_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71
72
			//return Redirect::route('admin.movies');			
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
		}
74
75
		$this->layout->content = View::make('admin.addmovie',[
76
			'info' => $info
77
		]);
78
	}
79
	
80
	public function confirmMovie() {
81
		// Create the league
82
		$movie = new Movie(Input::only([
83
			'title', 'release_date', 'boxmojo_id'
84
		]));
85
		$movie->name = Input::get('title');
86
		$movie->release = Input::get('release_date');
87
		$movie->boxmojo_id = Input::get('mojo_id');
88
		$movie->save();
89
		
90
		$earnings = unserialize(Input::get('grosses'));
91
		$latest_earnings_id = 0;
92
		$count = 0;
93
		foreach($earnings as $gross) { 
94
			$earnings = new MovieEarning([
95
				'movie_id' => $movie->id,
96
				'date'     => $gross['release_date'],
97
				'domestic' => $gross['domestic_total']
98
			]);
99
			$earnings->save();
100
			$latest_earnings_id = $earnings->id;
101
			$count += 1;
102
		}
103
		
104
		if($latest_earnings_id != 0) {
105
			$movie->latest_earnings_id = $latest_earnings_id;
106
			$movie->save();
107
		}
108
		
109
		Notification::success("Successfully added ".$movie->name." with ".$count." day(s) of earnings");
110
111
		return Redirect::route('admin.addMovie');
112
113
	}
114
	
115
	
116
}