AppImport   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 86.11 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 31
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 10 10 2
A camelize() 0 4 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
namespace CsvCombine\Import;
3
4
/**
5
 * AppImport
6
 * Import系のまとめ
7
 * @author hagiwara
8
 */
9 View Code Duplication
class AppImport {
0 ignored issues
show
Duplication introduced by
This class 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...
10
    protected $_defaultOptions = [
11
        'line_feed_code' => "\r\n",
12
        'array_encoding' => 'UTF-8',
13
        'import_encoding' => 'SJIS-win',
14
        // csvのみのオプション
15
        'delimiter' => ',',
16
        // 固定長のみのオプション
17
        'extra_fixed_options' => []
18
    ];
19
20
    /**
21
     * getOptions
22
     * 使用オプションのまとめ
23
     * @author hagiwara
24
     */
25
    protected function getOptions($options)
26
    {
27
        $options = array_merge($this->_defaultOptions, $options);
28
        // キーをすべてキャメライズする
29
        foreach ($options as $optionKey => $optionVal) {
30
            unset($options[$optionKey]);
31
            $options[$this->camelize($optionKey)] = $optionVal;
32
        }
33
        return $options;
34
    }
35
36
    /**
37
     * camelize
38
     * https://qiita.com/okapon_pon/items/498b88c2f91d7c42e9e8
39
     */
40
    private function camelize($str)
41
    {
42
        return lcfirst(strtr(ucwords(strtr($str, ['_' => ' '])), [' ' => '']));
43
    }
44
}
45