Completed
Push — master ( 4be90b...11f63d )
by Laurent
12:32 queued 08:08
created

ControllerHelper::testCreate()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.2
cc 4
eloc 11
nc 6
nop 2
1
<?php
2
/**
3
 * ControllerHelper Helpers de l'application GLSR.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version since 1.0.0
12
 *
13
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Helper;
16
17
use AppBundle\Entity\Article;
18
use Doctrine\Common\Persistence\ObjectManager;
19
20
/**
21
 * Controller helper.
22
 *
23
 * @category Helper
24
 */
25
class ControllerHelper
26
{
27
    /**
28
     * Tests of creation conditions.
29
     *
30
     * @param array Articles à tester
31
     * @return boolean
32
     */
33
    public function testSupplierHasArticle(array $articles)
0 ignored issues
show
Coding Style introduced by
function testSupplierHasArticle() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
34
    {
35
        $return = true;
36
37
        // This supplier has no articles!
38
        if (count($articles) < 1) {
39
            $message = $this->get('translator')->trans('settings.no_articles', array(), 'gs_suppliers');
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<AppBundle\Helper\ControllerHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            $this->addFlash('danger', $message);
0 ignored issues
show
Bug introduced by
The method addFlash() does not seem to exist on object<AppBundle\Helper\ControllerHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            $return = false;
42
        }
43
44
        return $return;
45
    }
46
47
    /**
48
     * Tests Order in progress for a supplier.
49
     *
50
     * @param \AppBundle\Entity\Article $articles Articles to test
51
     * @param \Doctrine\Common\Persistence\ObjectManager $etm Named object manager
52
     * @return boolean
53
     */
54
    public function testOrderInProgress(Article $articles, ObjectManager $etm)
0 ignored issues
show
Coding Style introduced by
function testOrderInProgress() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
55
    {
56
        $return = false;
57
        $orders = $etm->getRepository('AppBundle:Orders')->findAll();
58
        // This provider already has an order in progress!
59
        foreach ($orders as $order) {
60
            if ($order->getSupplier() === $articles->getSupplier()) {
61
                $return = true;
62
            }
63
        }
64
        return $return;
65
    }
66
}
67