Completed
Push — master ( 3f8d02...1b1905 )
by Mert S.
02:03
created

functions.php ➔ editLocal()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 3
nop 3
dl 0
loc 9
rs 9.6666
1
<?php
2
3
	function find($first, $latest, $text) {
4
		@preg_match_all("/" . preg_quote($first, "/") .
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...
5
		"(.*?)". preg_quote($latest, "/")."/i", $text, $m);
6
		return @$m[1];
7
	}
8
	
9
	function strtoupperEN($str) {
10
		$str = str_replace(array('i', 'ı', 'ü', 'ğ', 'ş', 'ö', 'ç', 'I', 'İ', 'Ü', 'Ğ', 'Ş', 'Ö', 'Ç'), array('I', 'I', 'U', 'G', 'S', 'O', 'C', 'I', 'I', 'U', 'G', 'S', 'O', 'C'), $str);
11
		return strtoupper($str);
12
	}
13
	
14
	function strtolowerTR($str) {
15
		$str = str_replace(array('i', 'ı', 'ü', 'ğ', 'ş', 'ö', 'ç', 'I', 'İ', 'Ü', 'Ğ', 'Ş', 'Ö', 'Ç'), array('i', 'ı', 'ü', 'ğ', 'ş', 'ö', 'ç', 'ı', 'i','ü', 'ğ', 'ş', 'ö', 'ç'), $str);
16
		return strtolower($str);
17
	}
18
	
19
	function ucwords_tr($gelen){
20
	 
21
		$sonuc = '';
22
		$kelimeler = explode(" ", $gelen);
23
24
		foreach ($kelimeler as $kelime_duz){
25
26
			$kelime_uzunluk = strlen($kelime_duz);
27
			$ilk_karakter = mb_substr($kelime_duz,0,1,'UTF-8');
28
29
			if($ilk_karakter == 'Ç' or $ilk_karakter=='ç'){
30
				$ilk_karakter = 'Ç';
31
			}elseif ($ilk_karakter=='Ğ' or $ilk_karakter=='ğ') {
32
				$ilk_karakter='Ğ';
33
			}elseif($ilk_karakter=='I' or $ilk_karakter=='ı'){
34
				$ilk_karakter='I';
35
			}elseif ($ilk_karakter=='İ' or $ilk_karakter=='i'){
36
				$ilk_karakter='İ';
37
			}elseif ($ilk_karakter=='Ö' or $ilk_karakter=='ö'){
38
				$ilk_karakter='Ö';
39
			}elseif ($ilk_karakter=='Ş' or $ilk_karakter=='ş'){
40
				$ilk_karakter='Ş';
41
			}elseif ($ilk_karakter=='Ü' or $ilk_karakter=='ü'){
42
				$ilk_karakter='Ü';
43
			}else{
44
				$ilk_karakter=strtoupper($ilk_karakter);
45
			}
46
47
			$digerleri=mb_substr($kelime_duz,1,$kelime_uzunluk,'UTF-8');
48
			$sonuc.=$ilk_karakter.kucuk_yap($digerleri).' ';
49
50
		}
51
52
		$son=trim(str_replace('  ', ' ', $sonuc));
53
		return $son;
54
	}
55
	
56
	function kucuk_yap($gelen){
57
	 
58
		$gelen=str_replace('Ç', 'ç', $gelen);
59
		$gelen=str_replace('Ğ', 'ğ', $gelen);
60
		$gelen=str_replace('I', 'ı', $gelen);
61
		$gelen=str_replace('İ', 'i', $gelen);
62
		$gelen=str_replace('Ö', 'ö', $gelen);
63
		$gelen=str_replace('Ş', 'ş', $gelen);
64
		$gelen=str_replace('Ü', 'ü', $gelen);
65
		$gelen=strtolower($gelen);
66
67
		return $gelen;
68
	}
69
	
70
	function hashtag($MultiWord){
71
		$MultiWord = strpos($MultiWord, " ");
72
		
73
		if	($MultiWord === false)	{$hashtag = "#";}
74
		else						{$hashtag = "";}
75
		return $hashtag;
76
	}
77
	
78
	function editLocal($localeEx, $fileop, $fileopUp){
79
		for ($y = 0; isset($fileop[$y]); $y++) {
80
			if ($localeEx == $fileopUp[$y]) {
81
				$localeTR = ucwords_tr(strtolowerTR($fileop[$y]));
82
				break;
83
			}
84
		}
85
		return $localeTR;
0 ignored issues
show
Bug introduced by
The variable $localeTR does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
86
	}