/** * Analyzes the given class * * @param PC_Obj_Class $class the class */ public function analyze($class) { // test whether abstract is used in a usefull way $abstractcount = 0; foreach ($class->get_methods() as $method) { if ($method->is_abstract()) { $abstractcount++; } } if (!$class->is_abstract() && $abstractcount > 0) { $this->report($class, 'The class "#' . $class->get_name() . '#" is NOT abstract but' . ' contains abstract methods!', PC_Obj_Error::E_S_CLASS_NOT_ABSTRACT); } // check super-class if ($class->get_super_class()) { // do we know the class? $sclass = $this->env->get_types()->get_class($class->get_super_class()); if ($sclass === null) { $this->report($class, 'The class "#' . $class->get_super_class() . '#" does not exist!', PC_Obj_Error::E_S_CLASS_MISSING); } else { if ($sclass->is_final()) { $this->report($class, 'The class "#' . $class->get_name() . '#" inherits from the final ' . 'class "#' . $sclass->get_name() . '#"!', PC_Obj_Error::E_S_FINAL_CLASS_INHERITANCE); } } } // check implemented interfaces foreach ($class->get_interfaces() as $ifname) { $if = $this->env->get_types()->get_class($ifname); if ($if === null) { $this->report($class, 'The interface "#' . $ifname . '#" does not exist!', PC_Obj_Error::E_S_INTERFACE_MISSING); } else { if (!$if->is_interface()) { $this->report($class, '"#' . $ifname . '#" is no interface, but implemented by class #' . $class->get_name() . '#!', PC_Obj_Error::E_S_IF_IS_NO_IF); } } } }
/** * @see FWS_Module::run() */ public function run() { $tpl = FWS_Props::get()->tpl(); if (!$this->class) { $this->report_error(); return; } $curl = PC_URL::get_mod_url(); $classname = $this->class->get_name(); // build class-declaration $declaration = ''; if (!$this->class->is_interface()) { if ($this->class->is_abstract()) { $declaration .= 'abstract '; } else { if ($this->class->is_final()) { $declaration .= 'final '; } } $declaration .= 'class '; } else { $declaration .= 'interface '; } $declaration .= $classname . ' '; if (!$this->class->is_interface() && ($cn = $this->class->get_super_class())) { $declaration .= 'extends <a href="' . $curl->set('name', $cn)->to_url() . '">' . $cn . '</a> '; } if (count($this->class->get_interfaces()) > 0) { $declaration .= !$this->class->is_interface() ? 'implements ' : 'extends '; foreach ($this->class->get_interfaces() as $if) { $declaration .= '<a href="' . $curl->set('name', $if)->to_url() . '">' . $if . '</a>, '; } $declaration = FWS_String::substr($declaration, 0, -1); } $declaration = FWS_String::substr($declaration, 0, -1) . ';'; $tpl->add_variables(array('classname' => $classname, 'declaration' => $declaration)); $classfile = $this->class->get_file(); // constants $consts = array(); foreach ($this->class->get_constants() as $const) { $consts[] = array('name' => $const->get_name(), 'type' => $const->get_type(), 'line' => $const->get_line(), 'url' => $this->get_url($classfile, $const)); } $tpl->add_variable_ref('consts', $consts); // fields $fields = array(); $cfields = $this->class->get_fields(); ksort($cfields); foreach ($cfields as $field) { $fields[] = array('name' => $field->get_name(), 'type' => (string) $field, 'line' => $field->get_line(), 'url' => $this->get_url($classfile, $field)); } $tpl->add_variable_ref('fields', $fields); // methods $methods = array(); $cmethods = $this->class->get_methods(); ksort($cmethods); foreach ($cmethods as $method) { $methods[] = array('name' => $method->get_name(), 'type' => $method->__ToString(), 'line' => $method->get_line(), 'url' => $this->get_url($classfile, $method), 'since' => implode(', ', $method->get_version()->get_min()), 'till' => implode(', ', $method->get_version()->get_max())); } $tpl->add_variable_ref('methods', $methods); if ($this->class->get_file() && $this->class->get_line()) { $source = PC_Utils::highlight_file($this->class->get_file()); } else { $source = ''; } $tpl->add_variables(array('source' => $source, 'file' => $this->class->get_file(), 'line' => $this->class->get_line(), 'since' => implode(', ', $this->class->get_version()->get_min()), 'till' => implode(', ', $this->class->get_version()->get_max()))); }