Completed
Pull Request — master (#1043)
by Sebastian
07:23 queued 11s
created

Provider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 20.63 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 7
c 3
b 2
f 0
lcom 2
cbo 3
dl 13
loc 63
ccs 0
cts 40
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A disableLogging() 0 3 1
A enableLogging() 0 3 1
B doPopulate() 0 26 4
A configureOptions() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace FOS\ElasticaBundle\Propel;
4
5
use FOS\ElasticaBundle\Provider\AbstractProvider;
6
7
/**
8
 * Propel provider.
9
 *
10
 * @author William Durand <[email protected]>
11
 */
12
class Provider extends AbstractProvider
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17
    public function doPopulate($options, \Closure $loggerClosure = null)
18
    {
19
        $queryClass = $this->objectClass.'Query';
20
        $nbObjects = $queryClass::create()->count();
21
22
        $offset = $options['offset'];
23
24
        for (; $offset < $nbObjects; $offset += $options['batch_size']) {
25
            $objects = $queryClass::create()
26
                ->limit($options['batch_size'])
27
                ->offset($offset)
28
                ->find()
29
                ->getArrayCopy();
30
            $sliceSize = count($objects);
31
            $objects = $this->filterObjects($options, $objects);
32
            if (!empty($objects)) {
33
                $this->objectPersister->insertMany($objects);
34
            }
35
36
            usleep($options['sleep']);
37
38
            if ($loggerClosure) {
39
                $loggerClosure($sliceSize, $nbObjects);
40
            }
41
        }
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    protected function disableLogging()
48
    {
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    protected function enableLogging($logger)
55
    {
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 View Code Duplication
    protected function configureOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        parent::configureOptions();
64
65
        $this->resolver->setDefaults(array(
66
            'clear_object_manager' => true,
67
            'debug_logging'        => false,
68
            'ignore_errors'        => false,
69
            'offset'               => 0,
70
            'query_builder_method' => 'createQueryBuilder',
71
            'sleep'                => 0
72
        ));
73
    }
74
}
75