Return $this in Entitys setters, so that they can be chained.

This commit is contained in:
Jan Böhmer 2019-02-24 12:54:11 +01:00
parent 7dbdb959b8
commit ee29ad3e5a
9 changed files with 99 additions and 44 deletions

View file

@ -151,9 +151,10 @@ abstract class Company extends StructuralDBElement
* Set the addres
* @param string $new_address the new address (with "\n" as line break)
*/
public function setAddress(string $new_address)
public function setAddress(string $new_address) : self
{
$this->address = $new_address;
return $this;
}
/**
@ -161,9 +162,10 @@ abstract class Company extends StructuralDBElement
*
* @param string $new_phone_number the new phone number
*/
public function setPhoneNumber(string $new_phone_number)
public function setPhoneNumber(string $new_phone_number) : self
{
$this->phone_number = $new_phone_number;
return $this;
}
/**
@ -171,9 +173,10 @@ abstract class Company extends StructuralDBElement
*
* @param string $new_fax_number the new fax number
*/
public function setFaxNumber(string $new_fax_number)
public function setFaxNumber(string $new_fax_number) : self
{
$this->fax_number = $new_fax_number;
return $this;
}
/**
@ -182,9 +185,10 @@ abstract class Company extends StructuralDBElement
* @param string $new_email_address the new e-mail address
*/
public function setEmailAddress(string $new_email_address)
public function setEmailAddress(string $new_email_address) : self
{
$this->email_address = $new_email_address;
return $this;
}
/**
@ -192,9 +196,10 @@ abstract class Company extends StructuralDBElement
*
* @param string $new_website the new website
*/
public function setWebsite(string $new_website)
public function setWebsite(string $new_website) : self
{
$this->website = $new_website;
return $this;
}
/**
@ -203,9 +208,10 @@ abstract class Company extends StructuralDBElement
* @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number
*
*/
public function setAutoProductUrl(string $new_url)
public function setAutoProductUrl(string $new_url) : self
{
$this->auto_product_url = $new_url;
return $this;
}
}

View file

@ -78,13 +78,14 @@ class Device extends PartsContainingDBElement
*
* @param integer $new_order_quantity the new order quantity
*/
public function setOrderQuantity(int $new_order_quantity)
public function setOrderQuantity(int $new_order_quantity) : self
{
if($new_order_quantity < 0)
{
throw new \InvalidArgumentException("The new order quantity must not be negative!");
}
$this->order_quantity = $new_order_quantity;
return $this;
}
/**
@ -93,9 +94,10 @@ class Device extends PartsContainingDBElement
* @param boolean $new_order_only_missing_parts the new "order_only_missing_parts" attribute
*
*/
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts)
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts) : self
{
$this->order_only_missing_parts = $new_order_only_missing_parts;
return $this;
}

View file

@ -176,17 +176,19 @@ class Footprint extends PartsContainingDBElement
*
* @throws Exception if there was an error
*/
public function setFilename(string $new_filename)
public function setFilename(string $new_filename) : self
{
$this->filename = $new_filename;
return $this;
}
/**
* Change the 3d model filename of this footprint
* @throws Exception if there was an error
*/
public function set3dFilename(string $new_filename)
public function set3dFilename(string $new_filename) : self
{
$this->filename = $new_filename;
return $this;
}
}

View file

@ -106,9 +106,10 @@ abstract class NamedDBElement extends DBElement
*
* @param string $new_name the new name
*/
public function setName(string $new_name)
public function setName(string $new_name) : self
{
$this->name = $new_name;
return $this;
}
}

View file

@ -226,10 +226,12 @@ class Orderdetail extends DBElement
* @param integer $new_supplier_id the ID of the new supplier
*/
public function setSupplierId(int $new_supplier_id)
public function setSupplierId(int $new_supplier_id) : self
{
throw new \Exception("Not implemented yet!");
//TODO;
return $this;
}
/**
@ -238,9 +240,10 @@ class Orderdetail extends DBElement
* @param string $new_supplierpartnr the new supplier-part-nr
*
*/
public function setSupplierpartnr(string $new_supplierpartnr)
public function setSupplierpartnr(string $new_supplierpartnr) : self
{
$this->supplierpartnr = $new_supplierpartnr;
return $this;
}
/**
@ -248,19 +251,21 @@ class Orderdetail extends DBElement
*
* @param boolean $new_obsolete true means that this part is obsolete
*/
public function setObsolete(bool $new_obsolete)
public function setObsolete(bool $new_obsolete) : self
{
$this->obsolete = $new_obsolete;
return $this;
}
/**
* Sets the custom product supplier URL for this order detail.
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
* @param $new_url string The new URL for the supplier URL.
* @throws Exception if there was an error
*/
public function setSupplierProductUrl(string $new_url)
{
$this->setAttributes(array('supplier_product_url' => $new_url));
$this->supplier_product_url = $new_url;
return $this;
}
}

View file

@ -780,12 +780,11 @@ class Part extends AttachmentContainingDBElement
* Set the description
*
* @param string $new_description the new description
*
* @throws Exception if there was an error
*/
public function setDescription(string $new_description)
public function setDescription(string $new_description) : self
{
$this->description = $new_description;
return $this;
}
/**
@ -796,7 +795,7 @@ class Part extends AttachmentContainingDBElement
* @throws Exception if the new instock is not valid
* @throws Exception if there was an error
*/
public function setInstock(int $new_instock, $comment = null)
public function setInstock(int $new_instock, $comment = null) : self
{
$old_instock = (int) $this->getInstock();
$this->instock = $new_instock;
@ -811,6 +810,8 @@ class Part extends AttachmentContainingDBElement
$new_instock,
$comment
);*/
return $this;
}
/**
@ -819,7 +820,7 @@ class Part extends AttachmentContainingDBElement
* @param $comment string A comment that should be associated with the withdrawal.
* @throws Exception if there was an error
*/
public function withdrawalParts(int $count, $comment = null)
public function withdrawalParts(int $count, $comment = null) : self
{
if ($count <= 0) {
throw new \Exception('Zahl der entnommenen Bauteile muss größer 0 sein!');
@ -844,6 +845,8 @@ class Part extends AttachmentContainingDBElement
);*/
$this->instock = $new_instock;
return $this;
}
/**
@ -852,7 +855,7 @@ class Part extends AttachmentContainingDBElement
* @param $comment string A comment that should be associated with the withdrawal.
* @throws Exception if there was an error
*/
public function addParts(int $count, string $comment = null)
public function addParts(int $count, string $comment = null) : self
{
//TODO
@ -876,6 +879,8 @@ class Part extends AttachmentContainingDBElement
);*/
$this->instock = $new_instock;
return $this;
}
/**
@ -884,11 +889,16 @@ class Part extends AttachmentContainingDBElement
* @param integer $new_mininstock the new count of parts which should be in stock at least
*
* @throws Exception if the new mininstock is not valid
* @throws Exception if there was an error
*/
public function setMinInstock(int $new_mininstock)
public function setMinInstock(int $new_mininstock) : self
{
if($new_mininstock < 0) {
throw new \InvalidArgumentException('$new_mininstock must be positive!');
}
$this->mininstock = $new_mininstock;
return $this;
}
/**
@ -898,9 +908,11 @@ class Part extends AttachmentContainingDBElement
*
* @throws Exception if there was an error
*/
public function setComment(string $new_comment)
public function setComment(string $new_comment) : self
{
$this->comment = $new_comment;
return $this;
}
/**
@ -917,12 +929,14 @@ class Part extends AttachmentContainingDBElement
*
* @throws Exception if there was an error
*/
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null)
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null) : self
{
$this->manual_order = $new_manual_order;
//TODO;
/* $this->order_orderdetail = $new_order_orderdetails_id; */
$this->order_quantity = $new_order_quantity;
return $this;
}
/**
@ -930,13 +944,13 @@ class Part extends AttachmentContainingDBElement
*
* @param integer|NULL $new_order_orderdetails_id @li the new order orderdetails ID
* @li Or, to remove the orderdetails, pass a NULL
*
* @throws Exception if there was an error
*/
public function setOrderOrderdetailsID($new_order_orderdetails_id) : void
public function setOrderOrderdetailsID($new_order_orderdetails_id) : self
{
//TODO
throw new \Exception("Not implemented yet...");
return $this;
}
/**
@ -944,9 +958,11 @@ class Part extends AttachmentContainingDBElement
*
* @param integer $new_order_quantity the new order quantity
*/
public function setOrderQuantity(int $new_order_quantity) : void
public function setOrderQuantity(int $new_order_quantity) : self
{
$this->order_quantity = $new_order_quantity;
return $this;
}
/**
@ -960,10 +976,12 @@ class Part extends AttachmentContainingDBElement
* @throws Exception if the new category ID is not valid
* @throws Exception if there was an error
*/
public function setCategoryID(int $new_category_id)
public function setCategoryID(int $new_category_id) : self
{
//TODO
throw new \Exception("Not implemented yet!");
return $this;
}
/**
@ -975,10 +993,12 @@ class Part extends AttachmentContainingDBElement
* @throws Exception if the new footprint ID is not valid
* @throws Exception if there was an error
*/
public function setFootprintID($new_footprint_id)
public function setFootprintID($new_footprint_id) : self
{
//TODO
throw new \Exception("Not implemented yet!");
return $this;
}
/**
@ -990,10 +1010,12 @@ class Part extends AttachmentContainingDBElement
* @throws Exception if the new storelocation ID is not valid
* @throws Exception if there was an error
*/
public function setStorelocationID($new_storelocation_id)
public function setStorelocationID($new_storelocation_id) : self
{
//TODO
throw new \Exception("Not implemented yet!");
return $this;
}
/**
@ -1005,10 +1027,12 @@ class Part extends AttachmentContainingDBElement
* @throws Exception if the new manufacturer ID is not valid
* @throws Exception if there was an error
*/
public function setManufacturerID($new_manufacturer_id)
public function setManufacturerID($new_manufacturer_id) : self
{
//TODO
throw new \Exception("Not implemented yet!");
return $this;
}
/**
@ -1016,9 +1040,11 @@ class Part extends AttachmentContainingDBElement
* @param $new_favorite_status bool The new favorite status, that should be applied on this part.
* Set this to true, when the part should be a favorite.
*/
public function setFavorite(bool $new_favorite_status)
public function setFavorite(bool $new_favorite_status) : self
{
$this->favorite = $new_favorite_status;
return $this;
}
/**
@ -1026,9 +1052,11 @@ class Part extends AttachmentContainingDBElement
* @param string $new_url The new url
* @throws Exception when an error happens.
*/
public function setManufacturerProductURL(string $new_url)
public function setManufacturerProductURL(string $new_url) : self
{
$this->manufacturer_product_url = $new_url;
return $this;
}
/**
@ -1040,10 +1068,12 @@ class Part extends AttachmentContainingDBElement
* @throws Exception if the new ID is not valid
* @throws Exception if there was an error
*/
public function setMasterPictureAttachementID($new_master_picture_attachement_id)
public function setMasterPictureAttachementID($new_master_picture_attachement_id) : self
{
//TODO
throw new \Exception("Not implemented yet!");
return $this;
}

View file

@ -146,13 +146,15 @@ class Pricedetail extends DBElement
* @li Example: if "price_related_quantity" is '10',
* you have to set here the price for 10 parts!
*/
public function setPrice(float $new_price) : void
public function setPrice(float $new_price) : self
{
if($new_price < 0)
{
throw new \InvalidArgumentException('$new_price must be positive!');
}
$this->price = $new_price;
return $this;
}
/**
@ -166,12 +168,14 @@ class Pricedetail extends DBElement
*
* @param integer $new_price_related_quantity the price related quantity
*/
public function setPriceRelatedQuantity(int $new_price_related_quantity) : void
public function setPriceRelatedQuantity(int $new_price_related_quantity) : self
{
if($new_price_related_quantity <= 0) {
throw new \InvalidArgumentException('$new_price_related_quantity must be greater 0!');
}
$this->price_related_quantity = $new_price_related_quantity;
return $this;
}
/**
@ -191,12 +195,14 @@ class Pricedetail extends DBElement
*
* @param integer $new_min_discount_quantity the minimum discount quantity
*/
public function setMinDiscountQuantity(int $new_min_discount_quantity)
public function setMinDiscountQuantity(int $new_min_discount_quantity) : self
{
if($new_min_discount_quantity <= 0 ){
throw new \InvalidArgumentException('$new_min_discount_quantity must be positive!');
}
$this->min_discount_quantity = $new_min_discount_quantity;
return $this;
}

View file

@ -72,9 +72,10 @@ class Storelocation extends PartsContainingDBElement
*
* @throws Exception if there was an error
*/
public function setIsFull(bool $new_is_full) : void
public function setIsFull(bool $new_is_full) : self
{
$this->is_full = $new_is_full;
return $this;
}
/**

View file

@ -100,7 +100,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
//Check if both elements compared, are from the same type:
if ($class_name != \get_class($another_element)) {
throw new \InvalidArgumentException(_('isChildOf() funktioniert nur mit Elementen des gleichen Typs!'));
throw new \InvalidArgumentException('isChildOf() funktioniert nur mit Elementen des gleichen Typs!');
}
if ($this->getID() == null) { // this is the root node
@ -238,9 +238,10 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* @param integer|null $new_parent_id @li the ID of the new parent element
* @li NULL if the parent should be the root node
*/
public function setParentID($new_parent_id)
public function setParentID($new_parent_id) : self
{
$this->parent_id = $new_parent_id;
return $this;
}
/**
@ -249,9 +250,10 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* @param string $new_comment the new comment
* @throws Exception if there was an error
*/
public function setComment(string $new_comment)
public function setComment(string $new_comment) : self
{
$this->comment = $new_comment;
return $this;
}
/********************************************************************************