rougin /
credo
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Rougin\Credo; |
||||||
| 4 | |||||||
| 5 | /** |
||||||
| 6 | * Model |
||||||
| 7 | * |
||||||
| 8 | * @package Credo |
||||||
| 9 | * @author Rougin Gutib <[email protected]> |
||||||
| 10 | * |
||||||
| 11 | * @property \CI_DB_query_builder $db |
||||||
| 12 | */ |
||||||
| 13 | class Model extends \CI_Model |
||||||
| 14 | { |
||||||
| 15 | use Traits\CredoTrait; |
||||||
| 16 | |||||||
| 17 | /** |
||||||
| 18 | * Deletes the specified ID of the model from the database. |
||||||
| 19 | * |
||||||
| 20 | * @param integer $id |
||||||
| 21 | * @return void |
||||||
| 22 | */ |
||||||
| 23 | 2 | public function delete($id) |
|||||
| 24 | { |
||||||
| 25 | 2 | $item = $this->find($id); |
|||||
| 26 | |||||||
| 27 | 2 | $this->credo->remove($item); |
|||||
| 28 | |||||||
| 29 | 2 | $this->credo->flush(); |
|||||
| 30 | 2 | } |
|||||
| 31 | |||||||
| 32 | /** |
||||||
| 33 | * Inserts a new row into the table. |
||||||
| 34 | * |
||||||
| 35 | * @param array $data |
||||||
| 36 | * @return integer |
||||||
| 37 | */ |
||||||
| 38 | 2 | public function insert(array $data) |
|||||
| 39 | { |
||||||
| 40 | 2 | $metadata = $this->metadata((string) get_class($this)); |
|||||
| 41 | |||||||
| 42 | 2 | $this->db->insert($metadata->getTableName(), $data); |
|||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 43 | |||||||
| 44 | 2 | $item = $this->find($lastId = $this->db->insert_id()); |
|||||
|
0 ignored issues
–
show
The method
insert_id() does not exist on CI_DB_query_builder. Did you maybe mean insert()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 45 | |||||||
| 46 | 2 | $this->credo->refresh($item); |
|||||
| 47 | |||||||
| 48 | 2 | return $lastId; |
|||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | /** |
||||||
| 52 | * Updates the selected row from the table. |
||||||
| 53 | * |
||||||
| 54 | * @param integer $id |
||||||
| 55 | * @param array $data |
||||||
| 56 | * @return boolean |
||||||
| 57 | */ |
||||||
| 58 | 2 | public function update($id, array $data) |
|||||
| 59 | { |
||||||
| 60 | 2 | $metadata = $this->metadata((string) get_class($this)); |
|||||
| 61 | |||||||
| 62 | 2 | $primary = $metadata->getSingleIdentifierColumnName(); |
|||||
|
0 ignored issues
–
show
The method
getSingleIdentifierColumnName() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. It seems like you code against a sub-type of Doctrine\Common\Persistence\Mapping\ClassMetadata such as Doctrine\ORM\Mapping\ClassMetadataInfo.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 63 | |||||||
| 64 | 2 | $this->db->where($primary, $id)->set((array) $data); |
|||||
| 65 | |||||||
| 66 | 2 | $result = $this->db->update($metadata->getTableName()); |
|||||
| 67 | |||||||
| 68 | 2 | $this->credo->refresh($this->find((integer) $id)); |
|||||
| 69 | |||||||
| 70 | 2 | return $result; |
|||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | /** |
||||||
| 74 | * Returns the metadata of an entity. |
||||||
| 75 | * |
||||||
| 76 | * @param string $class |
||||||
| 77 | * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata |
||||||
| 78 | */ |
||||||
| 79 | 4 | protected function metadata($class) |
|||||
| 80 | { |
||||||
| 81 | 4 | return $this->credo->getMetadataFactory()->getMetadataFor($class); |
|||||
| 82 | } |
||||||
| 83 | } |
||||||
| 84 |