ClicknLoadController::addcrypted2Action()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 53
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
ccs 27
cts 27
cp 1
rs 8.7155
cc 6
eloc 30
nc 4
nop 1
crap 6

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Tartana\Controller;
3
4
use League\Flysystem\Adapter\Local;
5
use League\Flysystem\Config;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Tartana\Util;
11
12
class ClicknLoadController extends Controller
13
{
14
15
	/**
16
	 * @Route("/flash/addcrypted2", name="clicknload")
17
	 */
18 2
	public function addcrypted2Action(Request $request)
19
	{
20
		$data = array(
21 2
			'success' => false,
22 2
			'message' => $this->get('Translator')->trans('TARTANA_CLICKNLOAD_ERROR_ADDING_TO_QUEUE')
23
		);
24
25 2
		preg_match('/\'(.*?)\'/', $request->get('jk'), $matches);
26
27 2
		if (count($matches) < 1) {
28
			return;
29
		}
30
31 2
		$key = hex2bin($matches[1]);
32
33 2
		$cp = @mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', '');
34 2
		@mcrypt_generic_init($cp, $key, $key);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
35 2
		$dec = @mdecrypt_generic($cp, base64_decode($request->get('crypted')));
36 2
		@mcrypt_generic_deinit($cp);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
37 2
		@mcrypt_module_close($cp);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
38
39 2
		$folder = $this->container->getParameter('tartana.config')['links']['folder'];
40 2
		$folder = Util::realPath($folder);
41
42 2
		if (!empty($folder)) {
43 2
			$fs = new Local($folder);
44
45 2
			$name = $request->get('package', rand(0, 1000)) . '.txt';
46
47
			// Sanitize content
48 2
			$content = '';
49 2
			foreach (preg_split('/\r\n|\r|\n/', $dec) as $file) {
50 2
				if (strpos($file, 'http://') !== 0) {
51 1
					continue;
52
				}
53
54 1
				$content .= $file . PHP_EOL;
55
			}
56
57 2
			$content = trim($content);
58
59 2
			if ($content) {
60 1
				$fs->write($name, $content, new Config());
61
62
				$data = array(
63 1
					'success' => true,
64 1
					'message' => $this->get('Translator')->trans('TARTANA_CLICKNLOAD_CONTENT_ADDED_TO_QUEUE')
65
				);
66
			}
67
		}
68
69 2
		return new JsonResponse($data);
70
	}
71
}
72