Completed
Push — master ( 37eca5...0dfdea )
by Ankit
02:50
created

database.example.php ➔ URL()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
  // Define database connection constants
3
  define('DB_HOST', 'localhost');
4
  define('DB_USER', 'root');
5
  define('DB_PASSWORD','');
6
  define('DB_NAME', 'openchat');
7
  define('URL', URL());
8
9 View Code Duplication
   function URL()
0 ignored issues
show
Duplication introduced by
This function 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...
Coding Style introduced by
URL uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
10
  {
11
    $http = "http://";
12
    @$host = $_SERVER['SERVER_NAME'];
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
13
    @$port = $_SERVER['SERVER_PORT'];
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
14
    $fol = "";
15
    if(@$_SERVER['SERVER_ADDR']!=NULL)
16
    {
17
        $fol = "/".explode('/', $_SERVER['PHP_SELF'])[1];
18
    }
19
    $url = $http.$host.":".$port.$fol;
20
    return $url;
21
  }
22
23