Completed
Push — master ( d8a850...2d4ad9 )
by
unknown
03:02
created

AkademikController::update()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 82
Code Lines 56

Duplication

Lines 40
Ratio 48.78 %

Importance

Changes 0
Metric Value
cc 8
eloc 56
nc 11
nop 2
dl 40
loc 82
rs 5.9273
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Bantenprov\Nilai\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Bantenprov\Nilai\Facades\NilaiFacade;
9
10
/* Models */
11
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Akademik;
12
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
13
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
14
use App\User;
15
16
/* Etc */
17
use Validator;
18
19
/**
20
 * The AkademikController class.
21
 *
22
 * @package Bantenprov\Akademik
23
 * @author  bantenprov <[email protected]>
24
 */
25
class AkademikController extends Controller
26
{
27
    /**
28
     * Create a new controller instance.
29
     *
30
     * @return void
31
     */
32
    protected $akademik;
33
    protected $siswa;
34
    protected $user;
35
    protected $nilai;
36
37
    public function __construct(Akademik $akademik, Siswa $siswa, User $user, Nilai $nilai)
38
    {
39
        $this->akademik = $akademik;
40
        $this->siswa = $siswa;
41
        $this->user = $user;
42
        $this->nilai = $nilai;
43
    }
44
45
    /**
46
     * Display a listing of the resource.
47
     *
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function index(Request $request)
51
    {
52
        if (request()->has('sort')) {
53
            list($sortCol, $sortDir) = explode('|', request()->sort);
54
55
            $query = $this->akademik->orderBy($sortCol, $sortDir);
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
56
        } else {
57
            $query = $this->akademik->orderBy('id', 'asc');
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
58
        }
59
60
        if ($request->exists('filter')) {
61
            $query->where(function($q) use($request) {
62
                $value = "%{$request->filter}%";
63
                $q->where('user_id', 'like', $value)
64
                    ->orWhere('id', 'like', $value);
65
            });
66
        }
67
68
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
69
        $response = $query->with('user')->with('siswa')->paginate($perPage);
70
                
71
        return response()->json($response)
72
            ->header('Access-Control-Allow-Origin', '*')
73
            ->header('Access-Control-Allow-Methods', 'GET');
74
    }
75
76
    /**
77
     * Show the form for creating a new resource.
78
     *
79
     * @return \Illuminate\Http\Response
80
     */
81
    public function create()
82
    {        
83
        $users = $this->user->all();
84
        $siswas = $this->siswa->all();
85
86
        foreach($users as $user){
87
            array_set($user, 'label', $user->name);
88
        }
89
90
        foreach($siswas as $siswa){
91
            array_set($siswa, 'label', $siswa->nama_siswa);
92
        }
93
        
94
        $response['user'] = $users;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
95
        $response['siswa'] = $siswas;
96
        $response['status'] = true;
97
98
        return response()->json($response);
99
    }
100
101
    /**
102
     * Display the specified resource.
103
     *
104
     * @param  \App\Nilai  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
105
     * @return \Illuminate\Http\Response
106
     */
107
    public function store(Request $request)
108
    {
109
        $akademik = $this->akademik;
110
111
        $bahasa_indonesia = $request->bahasa_indonesia;
112
        $bahasa_inggris = $request->bahasa_inggris;
113
        $matematika = $request->matematika;
114
        $ipa = $request->ipa;
115
116
        $total_nialai_akademik = $bahasa_indonesia + $bahasa_inggris + $matematika + $ipa;
117
118
        $validator = Validator::make($request->all(), [
119
            'user_id' => 'required|unique:akademiks,user_id',
120
            'siswa_id' => 'required|unique:akademiks,siswa_id',
121
            'bahasa_indonesia' => 'required',
122
            'bahasa_inggris' => 'required',
123
            'matematika' => 'required',
124
            'ipa' => 'required'
125
        ]);
126
127
        if($validator->fails()){
128
            $check = $akademik->where('user_id',$request->user_id)->orWhere('siswa_id',$request->siswa_id)->whereNull('deleted_at')->count();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
129
130
            if ($check > 0) {
131
                $response['message'] = 'Failed ! Username, Nama Siswa, already exists';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
132
            } else {
133
                $akademik->user_id = $request->input('user_id');
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
134
                $akademik->bahasa_indonesia = $request->input('bahasa_indonesia');
0 ignored issues
show
Documentation introduced by
The property bahasa_indonesia does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
135
                $akademik->siswa_id = $request->input('siswa_id');
0 ignored issues
show
Documentation introduced by
The property siswa_id does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
136
                $akademik->bahasa_inggris = $request->input('bahasa_inggris');
0 ignored issues
show
Documentation introduced by
The property bahasa_inggris does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
137
                $akademik->matematika = $request->input('matematika');
0 ignored issues
show
Documentation introduced by
The property matematika does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
138
                $akademik->ipa = $request->input('ipa');
0 ignored issues
show
Documentation introduced by
The property ipa does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
139
                $akademik->save();
140
141
                
142
                $check_akademik = $this->nilai->where('siswa_id', $request->input('siswa_id'));
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
143
                if($check_akademik->count() > 0){
144
                    $this->nilai->where('siswa_id', $request->input('siswa_id'))->update([
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
145
                        'user_id' => $request->input('user_id'),
146
                        'siswa_id' => $request->input('siswa_id'),
147
                        'akademik' => $total_nialai_akademik
148
                    ]);
149
                }else{
150
                    $this->nilai->create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
151
                        'user_id' => $request->input('user_id'),
152
                        'siswa_id' => $request->input('siswa_id'),
153
                        'akademik' => $total_nialai_akademik
154
                    ]);
155
                }
156
157
158
                $response['message'] = 'success';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
159
            }
160
        } else {
161
                //$akademik->user_id = $request->input('user_id');
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
162
                $akademik->user_id = $request->input('user_id');
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
163
                $akademik->bahasa_indonesia = $request->input('bahasa_indonesia');
0 ignored issues
show
Documentation introduced by
The property bahasa_indonesia does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
164
                $akademik->siswa_id = $request->input('siswa_id');
0 ignored issues
show
Documentation introduced by
The property siswa_id does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
165
                $akademik->bahasa_inggris = $request->input('bahasa_inggris');
0 ignored issues
show
Documentation introduced by
The property bahasa_inggris does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
166
                $akademik->matematika = $request->input('matematika');
0 ignored issues
show
Documentation introduced by
The property matematika does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
167
                $akademik->ipa = $request->input('ipa');
0 ignored issues
show
Documentation introduced by
The property ipa does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
168
                $akademik->save();
169
170
                $check_akademik = $this->nilai->where('siswa_id', $request->input('siswa_id'));
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
171
                if($check_akademik->count() > 0){
172
                    $this->nilai->where('siswa_id', $request->input('siswa_id'))->update([
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
173
                        'user_id' => $request->input('user_id'),
174
                        'siswa_id' => $request->input('siswa_id'),
175
                        'akademik' => $total_nialai_akademik
176
                    ]);
177
                }else{
178
                    $this->nilai->create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
179
                        'user_id' => $request->input('user_id'),
180
                        'siswa_id' => $request->input('siswa_id'),
181
                        'akademik' => $total_nialai_akademik
182
                    ]);
183
                }
184
185
                
186
                
187
188
            $response['message'] = 'success';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
189
        }
190
191
        $response['status'] = true;
192
193
        return response()->json($response);
194
    }
195
196
    /**
197
     * Store a newly created resource in storage.
198
     *
199
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
200
     * @return \Illuminate\Http\Response
201
     */
202
    public function show($id)
203
    {
204
        $akademik = $this->akademik->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
205
206
        $response['user'] = $akademik->user;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
207
        $response['akademik'] = $akademik;
208
        $response['siswa'] = $akademik->siswa;
209
        $response['status'] = true;
210
211
        return response()->json($response);
212
    }
213
214
    /**
215
     * Show the form for editing the specified resource.
216
     *
217
     * @param  \App\Nilai  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
218
     * @return \Illuminate\Http\Response
219
     */
220
    public function edit($id)
221
    {
222
        $akademik = $this->akademik->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
223
224
        array_set($akademik->user, 'label', $akademik->user->name);
225
        array_set($akademik->siswa, 'label', $akademik->siswa->nama_siswa);
226
227
        $response['akademik'] = $akademik;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
228
        $response['siswa'] = $akademik->siswa;
229
        $response['user'] = $akademik->user;
230
        $response['status'] = true;
231
232
        return response()->json($response);
233
    }
234
235
    /**
236
     * Update the specified resource in storage.
237
     *
238
     * @param  \Illuminate\Http\Request  $request
239
     * @param  \App\Nilai  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
240
     * @return \Illuminate\Http\Response
241
     */
242
    public function update(Request $request, $id)
243
    {   
244
        $response = array();
245
        $message  = array();
246
247
        $bahasa_indonesia = $request->bahasa_indonesia;
248
        $bahasa_inggris = $request->bahasa_inggris;
249
        $matematika = $request->matematika;
250
        $ipa = $request->ipa;
251
252
        $total_nialai_akademik = $bahasa_indonesia + $bahasa_inggris + $matematika + $ipa;
253
254
        $akademik = $this->akademik->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
255
256
            $validator = Validator::make($request->all(), [
257
                'user_id' => 'required|unique:akademiks,user_id,'.$id,
258
                'siswa_id' => 'required|unique:akademiks,siswa_id,'.$id,
259
                'bahasa_indonesia' => 'required',
260
                'bahasa_inggris' => 'required',
261
                'matematika' => 'required',
262
                'ipa' => 'required',
263
264
            ]);
265
266
        if ($validator->fails()) {
267
268
            foreach($validator->messages()->getMessages() as $key => $error){
269
                        foreach($error AS $error_get) {
270
                            array_push($message, $error_get);
271
                        }                
272
                    } 
273
274
             $check_user     = $this->akademik->where('id','!=', $id)->where('user_id', $request->user_id);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
275
             $check_siswa    = $this->akademik->where('id','!=', $id)->where('siswa_id', $request->siswa_id);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
276
277
             if($check_user->count() > 0 || $check_siswa->count() > 0){
278
                  $response['message'] = implode("\n",$message);
279 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
280
                $akademik->user_id    = $request->input('user_id');
281
                $akademik->bahasa_indonesia    = $request->input('bahasa_indonesia');
282
                $akademik->siswa_id = $request->input('siswa_id');
283
                $akademik->bahasa_inggris    = $request->input('bahasa_inggris');
284
                $akademik->matematika    = $request->input('matematika');
285
                $akademik->ipa    = $request->input('ipa');
286
                $akademik->save();                
287
288
                $check_akademik = $this->nilai->where('siswa_id', $request->input('siswa_id'));
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
289
                if($check_akademik->count() > 0){
290
                    $this->nilai->where('siswa_id', $request->input('siswa_id'))->update([
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
291
                        'user_id' => $request->input('user_id'),
292
                        'siswa_id' => $request->input('siswa_id'),
293
                        'akademik' => $total_nialai_akademik
294
                    ]);
295
                }
296
297
                $response['message'] = 'success';
298
            }
299 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
300
                $akademik->user_id    = $request->input('user_id');
301
                $akademik->bahasa_indonesia    = $request->input('bahasa_indonesia');
302
                $akademik->siswa_id = $request->input('siswa_id');
303
                $akademik->bahasa_inggris    = $request->input('bahasa_inggris');
304
                $akademik->matematika    = $request->input('matematika');
305
                $akademik->ipa    = $request->input('ipa');
306
                $akademik->save();
307
308
                $check_akademik = $this->nilai->where('siswa_id', $request->input('siswa_id'));
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
309
                if($check_akademik->count() > 0){
310
                    $this->nilai->where('siswa_id', $request->input('siswa_id'))->update([
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
311
                        'user_id' => $request->input('user_id'),
312
                        'siswa_id' => $request->input('siswa_id'),
313
                        'akademik' => $total_nialai_akademik
314
                    ]);
315
                }
316
317
            $response['message'] = 'success';
318
        }
319
320
        $response['status'] = true;
321
322
        return response()->json($response);
323
    }
324
325
    /**
326
     * Remove the specified resource from storage.
327
     *
328
     * @param  \App\Nilai  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
329
     * @return \Illuminate\Http\Response
330
     */
331
    public function destroy($id)
332
    {
333
        $akademik = $this->akademik->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
334
335
        if ($akademik->delete()) {
336
            $response['status'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
337
        } else {
338
            $response['status'] = false;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
339
        }
340
341
        return json_encode($response);
342
    }
343
}
344