File Email.php
has 1234 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
CI_Email
has 61 functions (exceeds 20 allowed). Consider refactoring. Open
class CI_Email {
/**
* Used as the User-Agent and X-Mailer headers' value.
*
Method _build_message
has 126 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _build_message()
{
if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
{
$this->_body = $this->word_wrap($this->_body);
Function _build_message
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
protected function _build_message()
{
if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
{
$this->_body = $this->word_wrap($this->_body);
- Read upRead up
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 _send_command
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _send_command($cmd, $data = '')
{
switch ($cmd)
{
case 'hello':
Function _prep_quoted_printable
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
protected function _prep_quoted_printable($str)
{
// ASCII code numbers for "safe" characters that can always be
// used literally, without encoding, as described in RFC 2049.
// https://www.ietf.org/rfc/rfc2049.txt
- Read upRead up
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 word_wrap
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function word_wrap($str, $charlim = NULL)
{
// Set the character limit, if not already present
if (empty($charlim))
{
- Read upRead up
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 _send_with_smtp
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _send_with_smtp()
{
if ($this->smtp_host === '')
{
$this->_set_error_message('lang:email_no_hostname');
Method word_wrap
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function word_wrap($str, $charlim = NULL)
{
// Set the character limit, if not already present
if (empty($charlim))
{
Method _prep_quoted_printable
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _prep_quoted_printable($str)
{
// ASCII code numbers for "safe" characters that can always be
// used literally, without encoding, as described in RFC 2049.
// https://www.ietf.org/rfc/rfc2049.txt
Function _send_with_smtp
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function _send_with_smtp()
{
if ($this->smtp_host === '')
{
$this->_set_error_message('lang:email_no_hostname');
- Read upRead up
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 _prep_q_encoding
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _prep_q_encoding($str)
{
$str = str_replace(array("\r", "\n"), '', $str);
if ($this->charset === 'UTF-8')
Function _send_command
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
protected function _send_command($cmd, $data = '')
{
switch ($cmd)
{
case 'hello':
- Read upRead up
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 _smtp_authenticate
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _smtp_authenticate()
{
if ( ! $this->_smtp_auth)
{
return TRUE;
Function _prep_q_encoding
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function _prep_q_encoding($str)
{
$str = str_replace(array("\r", "\n"), '', $str);
if ($this->charset === 'UTF-8')
- Read upRead up
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 _send_data
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function _send_data($data)
{
$data .= $this->newline;
for ($written = $timestamp = 0, $length = self::strlen($data); $written < $length; $written += $result)
{
- Read upRead up
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 batch_bcc_send
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function batch_bcc_send()
{
$float = $this->bcc_batch_size - 1;
$set = '';
$chunk = array();
Method _smtp_connect
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _smtp_connect()
{
if (is_resource($this->_smtp_connect))
{
return TRUE;
Method send
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function send($auto_clear = TRUE)
{
if ( ! isset($this->_headers['From']))
{
$this->_set_error_message('lang:email_no_from');
Function batch_bcc_send
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function batch_bcc_send()
{
$float = $this->bcc_batch_size - 1;
$set = '';
$chunk = array();
- Read upRead up
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 _send_data
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _send_data($data)
{
$data .= $this->newline;
for ($written = $timestamp = 0, $length = self::strlen($data); $written < $length; $written += $result)
{
Method attach
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function attach($file, $disposition = '', $newname = NULL, $mime = '')
{
if ($mime === '')
{
if (strpos($file, '://') === FALSE && ! file_exists($file))
Method from
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function from($from, $name = '', $return_path = NULL)
{
if (preg_match('/\<(.*)\>/', $from, $match))
{
$from = $match[1];
Function send
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function send($auto_clear = TRUE)
{
if ( ! isset($this->_headers['From']))
{
$this->_set_error_message('lang:email_no_from');
- Read upRead up
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 from
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function from($from, $name = '', $return_path = NULL)
{
if (preg_match('/\<(.*)\>/', $from, $match))
{
$from = $match[1];
- Read upRead up
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 _smtp_authenticate
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function _smtp_authenticate()
{
if ( ! $this->_smtp_auth)
{
return TRUE;
- Read upRead up
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 _write_headers
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function _write_headers()
{
if ($this->protocol === 'mail')
{
if (isset($this->_headers['Subject']))
- Read upRead up
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 initialize
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function initialize(array $config = array())
{
$this->clear();
foreach ($config as $key => $val)
- Read upRead up
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 attach
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function attach($file, $disposition = '', $newname = NULL, $mime = '')
{
if ($mime === '')
{
if (strpos($file, '://') === FALSE && ! file_exists($file))
- Read upRead up
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;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return FALSE;
Avoid too many return
statements within this method. Open
return FALSE;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return FALSE;
Avoid too many return
statements within this method. Open
return FALSE;
Avoid too many return
statements within this method. Open
return FALSE;
Function reply_to
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function reply_to($replyto, $name = '')
{
if (preg_match('/\<(.*)\>/', $replyto, $match))
{
$replyto = $match[1];
- Read upRead up
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
public function valid_email($email)
{
if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $email, $matches))
{
$domain = defined('INTL_IDNA_VARIANT_UTS46')
- Read upRead up
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 137.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches))
{
for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
$unwrap[] = $matches[1][$i];
- Read upRead up
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 105.
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