Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Sprawdzenie klasy
minolone
post
Post #1





Grupa: Zarejestrowani
Postów: 141
Pomógł: 24
Dołączył: 21.06.2008

Ostrzeżenie: (0%)
-----


Witam.
Prosze was o sprawdzenie klasy oraz wyrzucenie mi wszystkich błędów co jest nie tak jak być powinno.
Jest nie skończona ale wszytsko działa tak jak chciałem.
  1. <?php
  2.  
  3. print_r($_POST);
  4.  
  5. class AirConditioning {
  6.  
  7. const HOME = 20;
  8. const HOME_ROOF = 0.2;
  9. const COMPANY = 10;
  10. const COMPANY_PERCENT = 0.1;
  11. const COMPANY_ROOF = 0.1;
  12. const PEOPLE = 0.1;
  13.  
  14. private $people;
  15. //public $window;
  16. private $roof;
  17.  
  18. public function __construct($room, $height, $area, $people, $window, $roof) {
  19. $this->room = $room;
  20. $this->height = $height;
  21. $this->area = $area;
  22. if(!empty($window)) $this->window = $window;
  23. if(!empty($people)) $this->people = $people;
  24. if(!empty($roof)) $this->roof = $roof;
  25. }
  26.  
  27. public function check() {
  28. if($this->room == 0) {
  29. return $this->home($this->height, $this->area);
  30. }
  31. if($this->room == 1) {
  32. return $this->company($this->height, $this->area);
  33. }
  34. }
  35.  
  36. public function home($height, $area) {
  37. $count = $height*$area/self::HOME;
  38.  
  39. if($this->roof == 1) {
  40. $roof = self::HOME_ROOF;
  41. }
  42.  
  43. if($this->people > 0) {
  44. $people = $this->people($this->people);
  45. }
  46.  
  47. if(isset($roof) AND $roof > 0) {
  48. $count = $count+$count*$roof;
  49. }
  50.  
  51. if(isset($people) AND $people > 0) {
  52. $count = $count+$people;
  53. }
  54.  
  55. return $count;
  56. }
  57.  
  58. public function company($height, $area) {
  59. $count = $height*$area;
  60. $count = $count/self::COMPANY;
  61. $add = self::COMPANY_PERCENT;
  62.  
  63. if($this->roof == 1) {
  64. $add += self::COMPANY_ROOF;
  65. }
  66.  
  67. if($this->people > 0) {
  68. $people = $this->people($this->people);
  69. }
  70.  
  71. if(isset($roof) AND $roof > 0) {
  72. $count = $count+$count*$roof;
  73. }
  74.  
  75. if(isset($people) AND $people > 0) {
  76. $count = $count+$people;
  77. }
  78.  
  79. return $count;
  80. }
  81.  
  82. public function people($people) {
  83. $people = $people*self::PEOPLE;
  84. return $people;
  85. }
  86.  
  87. }
  88.  
  89. ?>




Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
minolone
post
Post #2





Grupa: Zarejestrowani
Postów: 141
Pomógł: 24
Dołączył: 21.06.2008

Ostrzeżenie: (0%)
-----


~rocktech.pl, myśle że "doc comment" sobie odpuścimy
proszę o sprawdzenie kodu czy jest to napisane w dość dobry sposób
pozdrawiam

  1. <?php
  2.  
  3. class AirConditioning
  4. {
  5.  
  6. const HOME = 20;
  7. const HOME_ROOF = 0.2;
  8. const COMPANY = 10;
  9. const COMPANY_PERCENT = 0.1;
  10. const COMPANY_ROOF = 0.1;
  11. const PEOPLE = 0.1;
  12.  
  13. public $people;
  14. public $roof;
  15.  
  16. public function __construct ($room, $height, $area, $people, $window, $roof)
  17. {
  18. $this->room = $room;
  19. $this->height = $height;
  20. $this->area = $area;
  21.  
  22. if (! empty($window)) {
  23. $this->window = $window;
  24. }
  25.  
  26. if (! empty($people)) {
  27. $this->people = $people;
  28. }
  29.  
  30. if (! empty($roof)) {
  31. $this->roof = $roof;
  32. }
  33. }
  34.  
  35. public function check ()
  36. {
  37. if ($this->room == 0) {
  38. return $this->home($this->height, $this->area);
  39. }
  40.  
  41. if ($this->room == 1) {
  42. return $this->company($this->height, $this->area);
  43. }
  44. }
  45.  
  46. public function home ($height, $area)
  47. {
  48. $count = $height * $area / self::HOME;
  49.  
  50. if ($this->roof == 1) {
  51. $roof = self::HOME_ROOF;
  52. }
  53.  
  54. if ($this->people > 0) {
  55. $people = $this->people($this->people);
  56. }
  57.  
  58. if (isset($roof) and $roof > 0) {
  59. $count = $count + $count * $roof;
  60. }
  61.  
  62. if (isset($people) and $people > 0) {
  63. $count = $count + $people;
  64. }
  65.  
  66. return $count;
  67. }
  68.  
  69. public function company ($height, $area)
  70. {
  71. $count = $height * $area;
  72. $count = $count / self::COMPANY;
  73. $add = self::COMPANY_PERCENT;
  74.  
  75. if ($this->roof == 1) {
  76. $add += self::COMPANY_ROOF;
  77. }
  78.  
  79. if ($this->people > 0) {
  80. $people = $this->people($this->people);
  81. }
  82.  
  83. if (isset($roof) and $roof > 0) {
  84. $count = $count + $count * $roof;
  85. }
  86.  
  87. if (isset($people) and $people > 0) {
  88. $count = $count + $people;
  89. }
  90.  
  91. return $count;
  92. }
  93.  
  94. public function people ($people)
  95. {
  96. $people = $people * self::PEOPLE;
  97. return $people;
  98. }
  99.  
  100. }
  101.  
  102. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 3.10.2025 - 06:35