HospitalForm::load()   B
last analyzed

Complexity

Conditions 3
Paths 12

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 3
eloc 19
nc 12
nop 3
1
<?php
2
3
/**
4
 * PatientCRUD
5
 *
6
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
7
 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8
 *
9
 * Permission is hereby granted to use or copy this program
10
 * for any purpose, provided the above notices are retained on all copies.
11
 * Permission to modify the code and to distribute modified code is granted,
12
 * provided the above notices are retained, and a notice that the code was
13
 * modified is included with the above copyright notice.
14
 *
15
 * @category  Wp
16
 * @package   Punction
17
 * @author    Andrzej Marcinkowski <[email protected]>
18
 * @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz
19
 * @license   MIT http://opensource.org/licenses/MIT
20
 * @version   1.0 $Format:%H$
21
 * @link      http://
22
 * @since     File available since Release 1.0.0
23
 * PHP Version 5
24
 */
25
namespace Hospitalplugin\Entities;
26
27
use Hospitalplugin\DB\DoctrineBootstrap;
28
use Hospitalplugin\utils\Utils;
29
use Hospitalplugin\Twig\EscapePLCharsExtension;
30
use Hospitalplugin\Entities\WardCRUD;
31
use Hospitalplugin\Twig\PLTwig;
32
33
class HospitalForm {
34
	public static function load($yaml, $class, $dir) {
0 ignored issues
show
Coding Style introduced by
load uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
35
		try {
36
			$em = DoctrineBootstrap::getEntityManager ();
37
			
38
			$userId = $userId = wp_get_current_user ()->ID;
39
			$ward = WardCRUD::getWardForUser ( $userId );
40
			$user = $em->find ( "\Hospitalplugin\Entities\User", $userId );
41
			
42
			if (! empty ( $_POST )) {
43
				$args = $_POST;
44
				$i = new $class ( $args );
45
				$i->setWard ( $ward );
46
				$i->setUser ( $user );
47
				$em->persist ( $i );
48
				$em->flush ();
49
			} else {
50
				$object = \Hospitalplugin\utils\YAML2Object::getObject ( $yaml );
51
				echo PLTwig::load ( $dir )->render ( 'form.twig', array (
52
						'infections' => $object 
53
				) );
54
			}
55
		} catch ( Exception $e ) {
0 ignored issues
show
Bug introduced by
The class Hospitalplugin\Entities\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...
56
			echo "ERR: " . $e;
57
		}
58
	}
59
}
60
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...