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

Provider::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 13
loc 13
ccs 0
cts 12
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
crap 2
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