imagecms/ImageCMS

View on GitHub
application/modules/translator/classes/PoFileManager.php

Summary

Maintainability
F
6 days
Test Coverage

File PoFileManager.php has 541 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace translator\classes;

use Gettext\Translations;
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php - About 1 day to fix

Function toArray has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    public function toArray($name, $type, $lang, $langOn = TRUE) {
        $path = $this->getPoFileUrl($name, $type, $lang);

        if (!FileOperator::getInstatce()->checkFile($path, $langOn)) {
            $error = FileOperator::getInstatce()->getErrors();
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function makePoFileData has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    private function makePoFileData($data = []) {
        $resultData = [];
        foreach ($data as $key => $po) {
            if ($po) {
                $po = $this->preparePoFileData((array) $po);
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function update has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    public function update($name, $type, $lang, $data) {
        $po_data = $this->toArray($name, $type, $lang);

        if ($po_data && array_key_exists('po_array', $po_data)) {
            foreach ($data as $origin => $values) {
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function prepareUpdateSettings has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    public function prepareUpdateSettings($data) {
        if (!isset($data['Project-Id-Version']) || !$data['Project-Id-Version']) {
            $data['projectName'] = '';
        } else {
            $data['projectName'] = $data['Project-Id-Version'];
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method prepareUpdateSettings has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function prepareUpdateSettings($data) {
        if (!isset($data['Project-Id-Version']) || !$data['Project-Id-Version']) {
            $data['projectName'] = '';
        } else {
            $data['projectName'] = $data['Project-Id-Version'];
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php - About 2 hrs to fix

PoFileManager has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

class PoFileManager
{

    /**
     * Templates folder path
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 2 hrs to fix

Method toArray has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function toArray($name, $type, $lang, $langOn = TRUE) {
        $path = $this->getPoFileUrl($name, $type, $lang);

        if (!FileOperator::getInstatce()->checkFile($path, $langOn)) {
            $error = FileOperator::getInstatce()->getErrors();
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php - About 2 hrs to fix

Function saas_update_one has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function saas_update_one($name, $type, $lang, $domain_path) {
        $this->setSaasUrl('/var/www/saas_data/mainsaas');
        $saas_file = $this->toArray($name, $type, $lang);

        if (isset($saas_file['po_array'])) {
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function prepareSettingsValues has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    private function prepareSettingsValues($line) {
        foreach ($this->po_settings_keys as $key) {
            if (preg_match('/' . $key . '/', $line)) {
                $from = strpos($line, ':');

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method prepareSettingsValues has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function prepareSettingsValues($line) {
        foreach ($this->po_settings_keys as $key) {
            if (preg_match('/' . $key . '/', $line)) {
                $from = strpos($line, ':');

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Function prepareSettingsArray has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    private function prepareSettingsArray($data = []) {
        if (!isset($data['projectName']) || !$data['projectName']) {
            $data['projectName'] = '';
        }

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method prepareSettingsArray has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function prepareSettingsArray($data = []) {
        if (!isset($data['projectName']) || !$data['projectName']) {
            $data['projectName'] = '';
        }

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Method prepareDomain has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function prepareDomain($domain) {
        $CI = &get_instance();
        $template = $CI->config->item('template');

        if ($template != 'administrator') {
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Method makePoFileSettings has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function makePoFileSettings($data = []) {
        if (!empty($data)) {
            $data = $this->prepareSettingsArray($data);
            $settings = [
                         'msgid ""',
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Method update has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function update($name, $type, $lang, $data) {
        $po_data = $this->toArray($name, $type, $lang);

        if ($po_data && array_key_exists('po_array', $po_data)) {
            foreach ($data as $origin => $values) {
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Method makePoFileData has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function makePoFileData($data = []) {
        $resultData = [];
        foreach ($data as $key => $po) {
            if ($po) {
                $po = $this->preparePoFileData((array) $po);
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Method save has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function save($name, $type, $lang, $data) {
        ksort($data, SORT_STRING | SORT_FLAG_CASE);

        $url = $this->getPoFileUrl($name, $type, $lang);

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 1 hr to fix

Function create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function create($name, $type, $lang, $settings) {
        if ($name && $type && $lang) {
            $url = $this->getPoFileUrl($name, $type, $lang);

            if (file_exists($url)) {
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function makePoFileSettings has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    private function makePoFileSettings($data = []) {
        if (!empty($data)) {
            $data = $this->prepareSettingsArray($data);
            $settings = [
                         'msgid ""',
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function exchangeTranslation has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function exchangeTranslation($data) {
        $langExchanger = $data['langExchanger'];
        $langReceiver = $data['langReceiver'];

        $typeExchanger = $data['typeExchanger'];
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function save has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function save($name, $type, $lang, $data) {
        ksort($data, SORT_STRING | SORT_FLAG_CASE);

        $url = $this->getPoFileUrl($name, $type, $lang);

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function prepareDomain has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function prepareDomain($domain) {
        $CI = &get_instance();
        $template = $CI->config->item('template');

        if ($template != 'administrator') {
Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid too many return statements within this method.
Open

            return FALSE;
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                        return $domain;
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return $domain;
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php - About 30 mins to fix

Function searchPoFileAutocomplete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function searchPoFileAutocomplete($name, $type, $lang, $searchString) {
        $poFile = $this->toArray($name, $type, $lang);
        $poFileData = $poFile['po_array'];
        $searchString = mb_strtolower(trim($searchString));

Severity: Minor
Found in application/modules/translator/classes/PoFileManager.php - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

                    case 'Language-Team':
                        $value = explode(' ', $value);
                        $this->po_settings['Language-Team-Name'] = isset($value[0]) ? $value[0] : '';
                        $value[1] = isset($value[1]) ? $value[1] : '';
                        $value[1] = str_replace('<', '', $value[1]);
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php and 1 other location - About 3 hrs to fix
application/modules/translator/classes/PoFileManager.php on lines 736..743

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 153.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

                    case 'Last-Translator':
                        $value = explode(' ', $value);
                        $this->po_settings['Last-Translator-Name'] = isset($value[0]) ? $value[0] : '';
                        $value[1] = isset($value[1]) ? $value[1] : '';
                        $value[1] = str_replace('<', '', $value[1]);
Severity: Major
Found in application/modules/translator/classes/PoFileManager.php and 1 other location - About 3 hrs to fix
application/modules/translator/classes/PoFileManager.php on lines 744..751

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 153.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

There are no issues that match your filters.

Category
Status