File PoFileManager.php
has 541 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace translator\classes;
use Gettext\Translations;
- Create a ticketCreate a ticket
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();
- Read upRead up
- Create a ticketCreate a ticket
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);
- Read upRead up
- Create a ticketCreate a ticket
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) {
- Read upRead up
- Create a ticketCreate a ticket
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'];
- Read upRead up
- Create a ticketCreate a ticket
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'];
- Create a ticketCreate a ticket
PoFileManager
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
class PoFileManager
{
/**
* Templates folder path
- Create a ticketCreate a ticket
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();
- Create a ticketCreate a ticket
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'])) {
- Read upRead up
- Create a ticketCreate a ticket
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, ':');
- Read upRead up
- Create a ticketCreate a ticket
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, ':');
- Create a ticketCreate a ticket
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'] = '';
}
- Read upRead up
- Create a ticketCreate a ticket
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'] = '';
}
- Create a ticketCreate a ticket
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') {
- Create a ticketCreate a ticket
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 ""',
- Create a ticketCreate a ticket
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) {
- Create a ticketCreate a ticket
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);
- Create a ticketCreate a ticket
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);
- Create a ticketCreate a ticket
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)) {
- Read upRead up
- Create a ticketCreate a ticket
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 ""',
- Read upRead up
- Create a ticketCreate a ticket
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'];
- Read upRead up
- Create a ticketCreate a ticket
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);
- Read upRead up
- Create a ticketCreate a ticket
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') {
- Read upRead up
- Create a ticketCreate a ticket
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;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $domain;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $domain;
- Create a ticketCreate a ticket
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));
- Read upRead up
- Create a ticketCreate a ticket
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]);
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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]);
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76